Django nested QuerySets
问题 I have a Django data model like this (data fields omitted): class Atom(Model): pass class State(Model): atom = ForeignKey(Atom) class Transition(Model): atom = ForeignKey(Atom) upstate = ForeignKey(State,related_name='uptrans') lostate = ForeignKey(State,related_name='lotrans') When I query, the fields to be restricted can be in either model, so it is easiest to query on Transition.objects.filter(...) since all fields in the other models can be reached through the foreign keys. Let's call the