Django object multiple exclude()

后端 未结 5 2191
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-30 22:20

Is there a way to do a query and exclude a list of things, instead of calling exclude multiple times?

5条回答
  •  渐次进展
    2020-12-30 22:46

    Based on your reply to Ned, it sounds like you just want to exclude a list of tags. So you could just use the in filter:

    names_to_exclude = [o.name for o in objects_to_exclude] 
    Foo.objects.exclude(name__in=names_to_exclude)
    

    Does that do what you want?

提交回复
热议问题