I am trying to create a query where I get a filtered list.
The model that I am calling the query on is:
class WorkoutRecord(models.Model):
challenge = models.ForeignKey(Challenge)
workout_email_sent = models.DateTimeField(default=datetime.now)
status = models.IntegerField(default=1)
My query is:
L = WorkoutRecord.objects.filter(status = 1, challenge.user = request.user, workout_email_sent__lt = today)
The error message I am getting is:
keyword can't be an expression
I know the issue is on the challenge.user = request.user
part of the query but I'm not sure how to write the query so it filters on this ForeignKey
properly.
Use __ to follow foreign key relationships in a queryset:
L = WorkoutRecord.objects.filter(status=1, challenge__user=request.user, workout_email_sent__lt=today)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With