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 filte开发者_开发问答r? Something like this:
kwargs['exclude_active_id'] = options['active']
Same idea as you're already implemented except use exclude instead of filter
精彩评论