一:表一的字段分析

class Sheep_Area(models.Model):
# models.AutoField()自增列,要显示自定义的自增列,必须定义primary=True
# area_id 这个是在数据库中存的名字,对应在浏览器显示的名字为verbose_name,这样方便阅读。
area_id = models.AutoField(primary_key=True, verbose_name='牧场编号')
# models.CharField()字符串字段,必须需要设置max_length,对应数据库中的 varchar(50),允许为空。
province = models.CharField(max_length=50,verbose_name='省份',null=True)
city = models.CharField(max_length=100,verbose_name='市',null=True)
district = models.CharField(max_length=50,verbose_name='区',null=True)
county = models.CharField(max_length=100,verbose_name='县',null=True)
town = models.CharField(max_length=100,verbose_name='乡镇',null=True)
# models.BooleanField() 布尔类型,默认值是False
isdelete = models.BooleanField(default=False, verbose_name='逻辑删除')
class Meta:
db_table = 'sheep_area' # 数据库中的表名
# class Meta 是一个类中嵌套的抽象类,主要目的是给基类Sheep_Area提供其他的信息,基类就负责表字段的设计
db_table 就是指明基类创建表的表名,如果不指定表名,默认是 sheep_sheep_area,小写app应用名_小写模型类名

二:表二的字段分析

class Sheep_Farm(models.Model):
farm_id = models.AutoField(primary_key=True, verbose_name='牧场编号')
farm_name = models.CharField(max_length=100, verbose_name='牧场名称')
address = models.CharField(max_length=300, verbose_name='牧场地址')
username = models.CharField(max_length=100, verbose_name='用户名', null=True)
phone = models.CharField(max_length=20, verbose_name='联系电话', null=True)
user_id = models.IntegerField(verbose_name='用户ID')
# blank=True 针对表单的,表示表单填写字段的时候,可以为空,否则必须有值,null=True是针对数据库的。
create_date = models.DateField(default=datetime.date.strftime(datetime.date.today(), "%Y-%m-%d"),verbose_name='创建日期', blank=True)
# area = models.ForeignKey(to='Sheep_Area', on_delete=models.CASCADE,null=True)
isdelete = models.BooleanField(default=False, verbose_name='逻辑删除')
# 外键的理解:https://blog.csdn.net/hpu_yly_bj/article/details/78939748
class Meta:
db_table = 'sheep_farm'

三:表三的字段分析

class Sheep_Fold(models.Model):
# 羊舍类型
# choice选择字段:用于页面上的选择框标签,需要先提供一个二维的二元元组,第一个元素表示存在数据库内真实的值,第二个表示页面上显示的具体内容
fold_choice = (
('', '育肥羊舍'),
('', '泌乳羊舍'),
('', '羔羊舍'),
('', '后备羊舍'),
('', '种公羊舍'),
('', '青年母羊舍'),
('', '成年母羊舍'),
('', '基本母羊舍'),
('', '待产羊舍'),
('', '隔离舍')
)
f_id = models.AutoField(primary_key=True, verbose_name='羊圈号')
f_name = models.CharField(max_length=50, null=True, verbose_name='羊圈名字')
f_type = models.CharField(max_length=10, choices=fold_choice, verbose_name='羊圈的类型')
# models.ForeignKey(),外键设置,关联了Sheep_Farm,表明了一对多的关系,Sheep_Farm是一,Sheep_Fold是多
# on_delete=models.CASCADE 表示层级删除,表示删除主表的数据后从表的数据也会删除。on_delete=models.SET_NULL 表示主表删除这条记录,从表将数据置空
farm = models.ForeignKey(to='Sheep_Farm', on_delete=models.CASCADE)
isdelete = models.BooleanField(default=False, verbose_name='逻辑删除') class Meta:
db_table = 'sheep_fold'

四:表四的字段分析

# 羊信息模型
class Sheep_Info(models.Model):
# 羊品种类型
type_choice = (
('', '萨能奶山羊 '),
('', '关中奶山羊'),
('', '其他')
)
# 性别
sex_choice = (
('', '公'),
('', '母')
)
# 级别
grade_choice = (
('', '特级'),
('', '一级'),
('', '二级')
)
status_choice = (
('','在场'),
('','活淘'),
('','死亡')
) # 羊的ID
s_id = models.AutoField(primary_key=True, verbose_name='羊ID号')
# 羊编号/耳号
sheep_number = models.IntegerField(null=False, verbose_name='羊编号/耳号')
# 设备号
equipment_number = models.CharField(max_length=20, verbose_name='设备号', null=True)
# 羊品种
sheep_type = models.CharField(max_length=3, choices=type_choice, verbose_name='羊品种')
# 性别
sex = models.CharField(max_length=2, choices=sex_choice, verbose_name='性别')
# 出生日期'
# birthday = models.CharField(max_length=20,default=datetime.date.strftime(datetime.date.today(), "%Y-%m-%d"),verbose_name='出生日期',blank=True,)
birthday = models.DateField(default=datetime.date.strftime(datetime.date.today(), "%Y-%m-%d"), verbose_name='出生日期')
# 初生重'
birthday_weight = models.FloatField(verbose_name='初生重')
# 断奶重
weaning_weight = models.FloatField(verbose_name='断奶重', blank=True, null=True)
# 成年体重
weight = models.FloatField(verbose_name='体重', blank=True, null=True)
# 羊的级别
grade = models.CharField(max_length=3, choices=grade_choice, verbose_name='羊的级别', blank=True)
# 种公羊射精量
ejaculatory_amount = models.CharField(max_length=3, choices=grade_choice, verbose_name='射精量', blank=True,null=True)
# 年均产奶量
avg_milk_year = models.FloatField(blank=True, null=True, verbose_name='年平均产奶量')
# 总产量
all_milk = models.FloatField(blank=True, null=True, verbose_name='终生总产量')
# 父代
father = models.CharField(blank=True, null=True, max_length=50, verbose_name='父代')
# 母代
mather = models.CharField(blank=True, null=True, max_length=50, verbose_name='母代')
# 羊圈外键:羊舍通过fold属性就能看到所有和自己关联的羊,也就是羊舍里面的每一头羊的信息。
fold = models.ForeignKey(to='Sheep_Fold', on_delete=models.CASCADE)
# 牧场外键
farm = models.IntegerField(verbose_name='所属养场')
# 羊现在的状态
sheep_status = models.CharField(max_length=3, choices=status_choice, verbose_name='羊现在的状态',default='')
# 逻辑删除
isdelete = models.BooleanField(default=False, verbose_name='逻辑删除')
class Meta:
db_table = 'sheep_info' 羊信息录入的前端
django之数据模型类的字段分析-LMLPHP

五:表五的字段分析

# 羊活淘的羊信息
class Sheep_Info_LiveOut(models.Model):
# 羊品种类型
type_choice = (
('', '萨能奶山羊 '),
('', '关中奶山羊'),
('', '其他')
)
# 性别
sex_choice = (
('', '公'),
('', '母')
)
# 级别
grade_choice = (
('', '特级'),
('', '一级'),
('', '二级')
)
status_choice = (
('','在场'),
('','活淘'),
('','死亡')
) # 羊的ID
s_id = models.AutoField(primary_key=True, verbose_name='羊ID号')
# 羊编号/耳号
sheep_number = models.IntegerField(null=False, verbose_name='羊编号/耳号')
# 设备号
equipment_number = models.CharField(max_length=20, verbose_name='设备号', null=True)
# 羊品种
sheep_type = models.CharField(max_length=3, choices=type_choice, verbose_name='羊品种')
# 性别
sex = models.CharField(max_length=2, choices=sex_choice, verbose_name='性别')
# 出生日期'
# birthday = models.CharField(max_length=20,default=datetime.date.strftime(datetime.date.today(), "%Y-%m-%d"),verbose_name='出生日期',blank=True,)
birthday = models.DateField(default=datetime.date.strftime(datetime.date.today(), "%Y-%m-%d"), verbose_name='出生日期')
# 初生重'
birthday_weight = models.FloatField(verbose_name='初生重')
# 断奶重
weaning_weight = models.FloatField(verbose_name='断奶重', blank=True, null=True)
# 成年体重
weight = models.FloatField(verbose_name='体重', blank=True, null=True)
# 羊的级别
grade = models.CharField(max_length=3, choices=grade_choice, verbose_name='羊的级别', blank=True)
# 种公羊射精量
ejaculatory_amount = models.CharField(max_length=3, choices=grade_choice, verbose_name='射精量', blank=True,null=True)
# 年均产奶量
avg_milk_year = models.FloatField(blank=True, null=True, verbose_name='年平均产奶量')
# 总产量
all_milk = models.FloatField(blank=True, null=True, verbose_name='终生总产量')
# 父代
father = models.CharField(blank=True, null=True, max_length=50, verbose_name='父代')
# 母代
mather = models.CharField(blank=True, null=True, max_length=50, verbose_name='母代')
# 羊圈外键
fold = models.ForeignKey(to='Sheep_Fold', on_delete=models.CASCADE)
# 牧场外键
farm = models.IntegerField(verbose_name='所属养场')
# 羊现在的状态
sheep_status = models.CharField(max_length=3, choices=status_choice, verbose_name='羊现在的状态',default='')
# 逻辑删除
isdelete = models.BooleanField(default=False, verbose_name='逻辑删除')
class Meta:
db_table = 'sheep_info_liveOut'

六:表六的字段分析

# 羊死亡的信息
class Sheep_Info_Death(models.Model):
# 羊品种类型
type_choice = (
('', '萨能奶山羊 '),
('', '关中奶山羊'),
('', '其他')
)
# 性别
sex_choice = (
('', '公'),
('', '母')
)
# 级别
grade_choice = (
('', '特级'),
('', '一级'),
('', '二级')
)
status_choice = (
('', '在场'),
('', '活淘'),
('', '死亡')
) # 羊的ID
s_id = models.AutoField(primary_key=True, verbose_name='羊ID号')
# 羊编号/耳号
sheep_number = models.IntegerField(null=False, verbose_name='羊编号/耳号')
# 设备号
equipment_number = models.CharField(max_length=20, verbose_name='设备号', null=True)
# 羊品种
sheep_type = models.CharField(max_length=3, choices=type_choice, verbose_name='羊品种')
# 性别
sex = models.CharField(max_length=2, choices=sex_choice, verbose_name='性别')
# 出生日期'
# birthday = models.CharField(max_length=20,default=datetime.date.strftime(datetime.date.today(), "%Y-%m-%d"),verbose_name='出生日期',blank=True,)
birthday = models.DateField(default=datetime.date.strftime(datetime.date.today(), "%Y-%m-%d"), verbose_name='出生日期')
# 初生重'
birthday_weight = models.FloatField(verbose_name='初生重')
# 断奶重
weaning_weight = models.FloatField(verbose_name='断奶重', blank=True, null=True)
# 成年体重
weight = models.FloatField(verbose_name='体重', blank=True, null=True)
# 羊的级别
grade = models.CharField(max_length=3, choices=grade_choice, verbose_name='羊的级别', blank=True)
# 种公羊射精量
ejaculatory_amount = models.CharField(max_length=3, choices=grade_choice, verbose_name='射精量', blank=True, null=True)
# 年均产奶量
avg_milk_year = models.FloatField(blank=True, null=True, verbose_name='年平均产奶量')
# 总产量
all_milk = models.FloatField(blank=True, null=True, verbose_name='终生总产量')
# 父代
father = models.CharField(blank=True, null=True, max_length=50, verbose_name='父代')
# 母代
mather = models.CharField(blank=True, null=True, max_length=50, verbose_name='母代')
# 羊圈外键
fold = models.ForeignKey(to='Sheep_Fold', on_delete=models.CASCADE)
# 牧场外键
farm = models.IntegerField(verbose_name='所属养场')
# 羊现在的状态
sheep_status = models.CharField(max_length=3, choices=status_choice, verbose_name='羊现在的状态', default='')
# 逻辑删除
isdelete = models.BooleanField(default=False, verbose_name='逻辑删除')
class Meta:
db_table = 'sheep_info_death'
05-11 17:10