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 c
s 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
Post a Comment