1👍
✅
That could be done using chain of relations:
Food.objects.filter(foodeaten__day__in=days,
foodeaten__day__user=request.user) \
.order_by('foodeaten__day__date')
By the way, I’m not sure why do you have user
on multiple models Food
and DayOfFood
. If you really need user relations on both of them, maybe make the field name more explicit with the user’s role in each model, otherwise you will get confused very quickly.
Source:stackexchange.com