Django/GAE:如何过滤foreignkey上的查询集?

时间:2021-11-08 02:34:21

I have two very simple classes Submission and Store

我有两个非常简单的类提交和存储

class Submission(models.Model):  
    title = models.CharField(max_length=50, null=True, blank=True)  
    description = models.CharField(max_length=200, null= True, blank=True)  
    store = models.ForeignKey(Store)  

class Store(models.Model):   
    store_name = models.CharField(max_length=200)  
    store_url = models.CharField(max_length=200)  

I'd like to look up all the Submissions for a particular Store, filtering by store_name.

我想查找一个特定存储的所有提交,通过store_name进行过滤。

In regular Django I can do something like

在《被解救的姜戈》中,我可以做一些类似的事情

Submission.objects.filter(store__store_name__exact=_myStoreName_)  

However this appears to be invalid database query in Django with Google Appengine (using the djangoappengine package).

但是,在使用谷歌Appengine的Django中,这似乎是无效的数据库查询(使用djangoappengine包)。

What can I do instead?

我该怎么办呢?

Thank you.

谢谢你!

1 个解决方案

#1


12  

inner_query = Store.objects.filter(store_name='storename')
submissions = Submission.objects.filter(store__in=inner_query)

#1


12  

inner_query = Store.objects.filter(store_name='storename')
submissions = Submission.objects.filter(store__in=inner_query)