SyntaxError: keyword argument repeated
19,966
You may just chain the excludes:
qs = qs.exclude(ptrf__istartswith='ptrf-mt23run1-')
qs = qs.exclude(ptrf__istartswith='ptrf-20251-')
It does not cause any extra queries this way - Django won't evaluate the queryset until necessary.
An alternative is to build up the filter with Q
objects.
from django.db.models import Q
q = Q(ptrf__istartswith='ptrf-mt23run1-') | Q(ptrf__istartswith='ptrf-20251-')
qs = qs.exclude(q)
Author by
SURYA VISWANATHAN
Updated on June 04, 2022Comments
-
SURYA VISWANATHAN almost 2 years
I have the below queryset,
site_list = SiverifyVerificationSite.objects.filter(pattern_id=int(p_id), if_target=bundle.obj.pattern.if_target).exclude(ptrf__istartswith='ptrf-mt23run1-')
It works if I give one exclude filter whereas If I include the second filter in exclude it throws (SyntaxError: keyword argument repeated). Ideally what I want is,
site_list = SiverifyVerificationSite.objects.filter(pattern_id=int(p_id), if_target=bundle.obj.pattern.if_target).exclude(ptrf__istartswith='ptrf-mt23run1-', ptrf__istartswith='ptrf-20251-')
Is there any operators to do this. Thanks.