[Answer]-Django exclude for same field with different values

1👍

I got it… Q objects… below link is pretty good…

http://www.michelepasin.org/blog/2010/07/20/the-power-of-djangos-q-objects/

Some code:

for rule in rules:
    negative_rules.append((rule.key.lower() + "__" + "iexact", rule.value))

negative_rules = reduce(operator.or_, [Q(x) for x in negative_rules]) if negative_rules else Q()

Obj.objects.exclude(negative_rules)

Leave a comment