开发者

How to exclude manytomany object in query?

开发者 https://www.devze.com 2023-03-21 20:04 出处:网络
I created my own manager: class DataManager(models.Manager): def optfilter(self, options = dict()): kwargs = dict()

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

0

精彩评论

暂无评论...
验证码 换一张
取 消