Home > other >  Django model field constraint content
Django model field constraint content

Time:09-23

A teacher's table, a class list
 
The class the Teacher (models. Model) :
Name=models. CharField (max_length=10)
Subject=models. CharField (max_length=10)

Class Classname (models. Model) :
Grade=models. CharField (max_length=10)
Class_no=models. PositiveSmallIntegerField ()
Teacher_chinese=models. ForeignKey (the Teacher,
On_delete=models. PROTECT,
Related_name='teacher_c')
Teacher_math=models. ForeignKey (the Teacher,
On_delete=models. PROTECT,
Related_name='teacher_m')
Teacher_english=models. ForeignKey (the Teacher,
On_delete=models. PROTECT,
Related_name='teacher_e')

The class Meta:
Unique_together=(' grade ', 'class_no)

Class teacher_chinese can only is the teacher of the subject in the table is the Chinese teacher
How do I achieve?

CodePudding user response:

When inserting data to judgment
  • Related