Skip to content Skip to sidebar Skip to footer

Django Getting Queryset.values() Based On Condition

Let's say I have a model Class Parent and a Class Child. And child has a field called status and a ForeignKey relationship to Parent. Let's say I retrieve one parent by calling fil

Solution 1:

p = Parent.objects.filter(age=50)
sick_children = p.filter('children__status='sick').values('children__name')

The queryset will not be modified unless you assign the filter to p.


Post a Comment for "Django Getting Queryset.values() Based On Condition"