Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django/GAE: How to filter query set on foreignkey?

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.

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).

What can I do instead?

Thank you.

like image 406
Eitan Avatar asked Nov 28 '10 21:11

Eitan


1 Answers

inner_query = Store.objects.filter(store_name='storename')
submissions = Submission.objects.filter(store__in=inner_query)
like image 173
Josh Smeaton Avatar answered Oct 21 '22 09:10

Josh Smeaton