Why not use a lookup: TheA = ... TheCs = C.objects.filter(b__a = TheA) Le 8 juin 2012 15:01, "bo.schwarzst...@gmail.com" <bo.schwarzst...@gmail.com> a écrit :
> ** > Hi all, > > Is there any guideline about SQL performance ? > > For example, now we have 3 models, > > class A(Model): > ... > > class B(Model): > a = ForeignKey(A) > ... > > class C(Model): > b = ForeignKey(B) > ... > > the most database records are instances of C, user need to access C from > B, B from A under the hierarchical structure, now I collect the instances > of C like this, > > theA = A.objects.get(name = 'theA') > theBs = theA.b_set.filter(a = theA) > for theB in theBs: > theCs = theB.c_set.all() > > So should I add a new ForeignKey to C and filter the objects by (a = > theA, b = theB) ? Is there any performance impact for SQL database ? > Thanks ! > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-users@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.