Django Filter Foreignkey Field
Short version: I have a Django app used for recipes, and want to filter data to be sent to a template in my view. I basically want all recepies that are added by a specific user to
Solution 1:
You can try like:
recipes = Recipe.objects.filter(added_by__username = uname)
And request.user
works fine for Recipe.objects.filter(added_by = request.user)
because request.user
is an object. details: https://docs.djangoproject.com/en/dev/topics/db/queries/#lookups-that-span-relationships
Post a Comment for "Django Filter Foreignkey Field"