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.
Unexpected keyword argument %r in %s call. Description: Used when a function call passes a keyword argument that doesn't correspond to one of the function's parameter names.
An important detail to be aware of is that by default any argument used to call a function in Python can be used as both a positional and a keyword argument—just not at the same time.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With