开发者

Django filter against Multiple Item QuerySets

开发者 https://www.devze.com 2023-04-01 23:37 出处:网络
I have two Model\'s which are related with a ForeignKey field. Let\'s call these objects Event and EventRegistration.

I have two Model's which are related with a ForeignKey field. Let's call these objects Event and EventRegistration.

I can easily, for example, do this:

EventRegistration.objects.filter开发者_如何学运维(event=Event.objects.get(name="Some Event"))

But, I cannot do something like this:

EventRegistration.objects.filter(event=Event.objects.all())

I know this is a contrived example, but is there a way to filter against whole QuerySets in a similar way to the second line of code?


EventRegistration.objects.filter(event__in=Event.objects.all())
0

精彩评论

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