How does django use mysql database to query the database_Mysql database usage (Django), mysql, usage, django

One-to-many: Many-party definition foreign key!! # Student model class class Student( AbstractUser): mobile = models.CharField(max_length=11, unique=True, verbose_name='Mobile phone number') cid = models.ForeignKey(to=”Class”, to_field=”id”) class Meta: db_table = 'tb_student' verbose_name = 'user' verbose_name_plural = verbose_name # Class Model Class class Class(models.Model): id = models.AutoField(primary_key=True) cname &# 61; models.CharField(max_length=32) cdata = models.DateField() Implementing many-to-one in django When specifying , the usage is as follows: st = Student( username=student_name, password=password, cid=cl # cl is an instance of Class class ) In progress When searching : # One-to-many/many-to-one cl = Banji.objects.get(id& #61;3) tea = cl.student_set.all()[0] print(tea) print(cl.student_set .first()) st = Student.objects.get(username='fenghua') print(st.cid_id) print(st.cid.cname) Related query 1. Forward search (check more than 1): Get through the foreign key of the model class (here is cid) st.cid_id Find the class id corresponding to the student There is a field to_field=id when multiple parties define foreign keys in the model st.cid.cname Find the class name corresponding to the student 2. Reverse search (1 check more): If related_name is not set in the foreign key field& #xff0c;By default, the multi-party model lowercase _set is used. If related_name=”students”, is set, students can be used directly for reverse query cl (assumed to be a class object) cl.Model name lower case_set.first()…

Analyze Java abstract classes and interfaces in simple terms [functions, definitions, usage, differences]

The examples in this article describe Java abstract classes and interfaces. Share it with everyone for your reference, the details are as follows: For OOP programming, abstraction is one of its major features. In Java, OOP abstraction can be embodied in two forms: abstract classes and interfaces. The two have similarities but also significant differences. 1. Abstract class Before understanding abstract classes, first understand abstract methods. An abstract method is a special kind of method: only a declaration, but no concrete implementation. The declaration format of an abstract method is: abstract void fun(); Abstract methods must be modified with the abstract keyword. If a class contains an abstract method, it is called an abstract class. This class must be modified with abstract before the class, otherwise an error will be prompted when compiling in the IDE. Because abstract classes contain methods that have no concrete implementation, objects cannot be created using abstract classes. There is another issue to note: an abstract class modified with abstract does not need to contain abstract methods. Personally, I think this is a tricky question, because if an abstract class does not contain any abstract methods, why should it be designed as an abstract class?…

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索