One, multi-table query
With data table class and Classusertemp table
The requirement is to filter out all the data classusertemp the class under which a user luser management.
The owner field of the class table represents the associated administrator user.
You only need to use the associated property, the condition path is the class---class administrator--compared with the user
puserclasses = ClassUserTemp.objects.filter (Idclass__owner=luser)
Second, foreign key query
Need to change, to query a user in the Classusertemp records, the corresponding class
Comb, the condition path, classusertemp the user's record Iduser=luser can.
But the return class of the objects, at this time with Classusertemp foreign key Fkclassusertemp2class Connect class and Classusertemp table
Class.objects.filter (Fkclassusertemp2class__iduser=luser)
Appendix: Values Filtering
A table returns the results of a query and may just filter some of the fields to the user, so that you can use the values method on the query result set
User Table Structure Section
Define User table visible fields
The query result set is handled as follows, and it is worth noting that the "|" Represents merge Collection
Luser = User.objects.filter (Phonenumber=pkey) | User.objects.filter (Username__contains=pkey)
Luser = Luser.distinct (). VALUES (*globalvar.tablefields.userfields)
Queryset Other field meanings
Filter indicates that =,exclude represents! =.
Queryset.distinct () to repeat
__exact exactly equals like ' AAA '
__iexact precision equals ignoring case ilike ' AAA '
__contains contains like '%aaa% '
__icontains includes ignoring case ilike '%aaa% ', but for SQLite, the effect of contains is equivalent to Icontains.
__GT Greater than
__gte greater than or equal to
__lt less than
__lte less than or equal to
__in exists in a list range
__startswith to ... Beginning
__istartswith to ... Start ignoring case
__endswith to ... End
__iendswith to ... End, ignoring case
__range in ... Within range
__year Year of Date field
__month Month of Date field
Day of the __day date field
__isnull=true/false
"Service Backend" Django Multi-table data query