? c. 通用参数
######demoapp/model.py######
from django.db import models
# Create your models here.
from django.db import models
# Create your models here.
class Role(models.Model):
????????role_name = models.CharField(max_length=32, unique=True)
????????class Meta:
????????????????db_table = "pp_role"
class Classroom(models.Model)
class_name = models.CharField(max_length=32,verbose_name="班级名称",unique=True)
address = models.CharField(max_length=32,null=True)
class Meta:
????????db_table = "pp_class"
????????def __str__(self):
????????return self.class_name
class User(models.Model):
username = models.CharField(max_length=32,verbose_name="姓名")
age =models.IntegerField(verbose_name="年龄")
home = models.CharField(verbose_name="家乡",null=True,max_length=32)
hight = models.IntegerField(verbose_name="身?",null=True)
#多对多
roles = models.ManyToManyField(Role)
#?对多
classrooms = models.ForeignKey(Classroom,on_delete=models.CASCADE,null=True,related_name="u sers")#related_name参数为设置你想查找关键字