Python-django's ORM

Source: Internet
Author: User

    • 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.