首页 > 其他 > 详细

models_01

时间:2020-11-20 23:47:11      阅读:53      评论:0      收藏:0      [点我收藏+]
from django.db import models

models.CharField()


# Create your models here.

class Projects(models.Model):
name = models.CharField(verbose_name=‘项目名称‘, max_length=64, unique=True, help_text=‘项目名称‘)
leader = models.CharField(verbose_name=‘负责人‘, max_length=64, help_text=‘负责人‘)
tester = models.CharField(verbose_name=‘测试人员‘, max_length=64, help_text=‘测试人员‘)
developer = models.CharField(verbose_name=‘开发人员‘, max_length=64, help_text=‘开发人员‘)
publish_app = models.CharField(verbose_name=‘发布应用‘, max_length=200, help_text=‘发布应用‘)
# 长文本:TextField 前端可不传递:blank 默认值:default 允许为空:null
desc = models.TextField(verbose_name=‘简要描述‘, blank=True, default=‘‘, null=True, help_text=‘简要描述‘)

# 定义子类:设置当前数据模型的元信息
class Meta:
db_table = ‘tb_project‘

# 在admin站点中,显示一个更加人性化的表明
verbose_name = ‘项目‘
verbose_name_plural = ‘项目‘


class Book(models.Model):
title = models.CharField(max_length=64, verbose_name="书名")
price = models.IntegerField(verbose_name="价格", editable=True)
color = models.CharField(max_length=64, verbose_name="颜色")
page_num = models.IntegerField(null=True, editable=True)

# 一对多
publisher = models.ForeignKey("Publish", on_delete=models.CASCADE, verbose_name="出版社")

# 创建个新表
author = models.ManyToManyField("Author", verbose_name="作者")
# ManyToManyField: 可用两个ForeignKey

def __str__(self):
return self.title


class Author(models.Model):
name = models.CharField(max_length=30)

def __str__(self):
return self.name


# class Book_To_Author(models.Model):
# book = models.ForeignKey("Book", on_delete=models.CASCADE)
# author = models.ForeignKey("Author", on_delete=models.CASCADE)

# 组合唯一
# class Mete:
# unique_together = ["book", "author"]


class Publish(models.Model):
name = models.CharField(max_length=64)
city = models.CharField(max_length=63)

def __str__(self):
return self.name

models_01

原文:https://www.cnblogs.com/zxy01/p/14013314.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!