Django: Is it possible to retrieve a set of related objects from multiple nested levels? -


say have following models:

class a(models.model):     pass  class b(models.model):     = models.foreignkey(a, related_name='bs') 

if want retrieve set of b's specific a has, following:

a = a.objects.get(pk=[whatever]) a.bs.all() 

now, if add following model:

class c(models.model):     b = models.foreignkey(b, related_name='cs') 

how can cs specific a has? tried:

a = a.objects.get(pk=[whatever]) a.bs.cs.all() 

but doesn't work. possible? if is, how can achieve it?

you can do:

cs = c.objects.filter(b__a__pk=[whatever]) 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -