I have a Django data model similar to 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 request, the fields that need to be limited can be in any model, so the easiest way to request is Transition.objects.filter(...), since all fields in other models can be accessed through foreign keys. Let me call the resulting QuerySet t.
Now I want to add a QuerySet to aan Atom model that matches twhat can be done like a = t.values('atom').distinct(). So far so good.
However, I also want each of the entries in to ahave one attribute / field that contains a QuerySet for the states of this atom, still reflecting the criteria for the original selection t, through one of upstateor lostateForeignKeys.
QuerySet , t, values('upstate_id') values('lostate_id') Python set() . .
, , , , QuerySet s, , (yield), .