- class represents a database table
- The object of the class refers to a row of records in the database
- The FK field refers to a row of data in the associated table
- Manytomany field, automatically generates the third table: Dependency table indirect operation on third table
- Forward: FK field; reverse: Lowercase class name) _set =>releated_name= ' ssss '
- Who is the main table? All of its data is listed
- Models. Student.object.all (). VALUES (' Useename ', ' cs__title ')
- Models. Classes.object.all (). VALUES (' tittle ', ' ssss__username
Example:
-Names of all students and their class names, QuerySet
Stu_list = Student.objects.all ()
SELECT * from TB;
[Obj,obj,obj,obj]
Stu_list = Student.objects.all (). VALUES ("id", ' username ')
Select Id,username from TB;
[{"id": 1, ' username ': ' xx '},{id: ', Username: '}]
Stu_list = Student.objects.all (). Values_list ("id", ' username ')
[(1, ' Root '), (2, ' Alex ')]
Stu_list = Student.objects.all (). VALUES (' username ', ' cs__name ')
For row in Stu_list:
Print (row[' username '],row[' cs__name ')
Stu_list = Student.objects.all (). VALUES (' username ', "cs__titile", "Cs__fk__name")
Python-django's ORM