i want perform filter operation on queryset of form (x=true) or ((x=false) , (some other condition)). when try following command, error. suggestions.
operation
item.objects.filter(mission_id__in=mission_ids).exclude(id__in=attempted_items).filter( answers_left_count__gte=1, is_active=true, is_test_data=false ).values_list("mission_id", 'mission__items_per_mission', 'mission__send_remaining_items').annotate( count('id') # item count ).filter(q(mission__send_remaining_items=true) | ( q(mission__send_remaining_items=false), q(id__count__gte=f('mission__items_per_mission') + 1))).values_list( "mission_id", flat=true)
error
typeerror: (<q: (and: ('mission__send_remaining_items__is', false))>, <q: (and: ('id__count__gte', <combinedexpression: f(mission__items_per_mission) + value(1)>))>)
i want perform filter operation on queryset of form (x=true) or ((x=false) , (some other condition))
and
,
q
objects when directly passed filter()
, i.e.
.filter(q(), q())
but that's because of how filter()
processes arguments, not result of combining 2 q
objects.
anding q
objects done via &
:
.filter(q() & q())
so query becomes
.filter(q() | (q() & q()))
Comments
Post a Comment