django - Remove (filter out) objects from queryset -
i'd remove 3 objects queryset. working of list, im pretty sure there should better way queryset api. didnt figure out how yet:
what i'm doing:
ranks = rank.objects.all() remove_ranks = ['field marshall', 'military attache', 'mercenary recruiter'] new_ranks =[] rank in ranks: if not rank.name in remove_ranks: new_ranks.append(rank)
how can using django api ?
try
remove_ranks = ['field marshall', 'military attache', 'mercenary recruiter'] rank.objects.exclude(name__in=remove_ranks)
what do?
.exclude
opposite of .filter
name__in
equivalent of in-statement in sql
this should produce sql query along line
select * rank name not in ('field marshall', 'military attache', 'mercenary recruiter')
Comments
Post a Comment