Nips
Nips

Reputation: 13880

How to exclude manytomany object in query?

I created my own manager:

class DataManager(models.Manager):

    def optfilter(self, options = dict()):

    kwargs = dict()
    if options.has_key('active'):
        kwargs['active__id'] = options['active']

    return self.filter(**kwargs)

active is ManyToMany field.

and it working exacly as I want. But what about when I want exclude object from filter? Something like this:

kwargs['exclude_active_id'] = options['active']

Upvotes: 0

Views: 743

Answers (1)

John
John

Reputation: 5206

Same idea as you're already implemented except use exclude instead of filter

Upvotes: 1

Related Questions