zoukankan      html  css  js  c++  java
  • models.py 文件中的类及相关属性

    models中的类以及相关属性

    #作者表
    class Author(models.Model):
        name = models.CharField(max_length=16)
        #作者和作者详细表一对一关联
        detail = models.OneToOneField(to='AuthorDetail',on_delete=models.CASCADE)
        #作者和书的关系是多对多
        books = models.ManyToManyField(to='Book')
        def __str__(self):
            self.name
    
    #作者详情表
    class AuthorDetail(models.Model):
        city = models.CharField(max_length=32)
        email = models.EmailField()
    
    
    #书籍表
    class Book(models.Model):
        title = models.CharField(max_length=16)
        price = models.DecimalField(max_digits=5,decimal_places=2)    #最多5位数,,小数点保留后两位
    
        # auto_now=True 每一次修改都自动更新时间,auto_now_add =True 第一次创建时自动填入时间
        publish_day = models.DateField(auto_now_add=True)
        # 书和出版社对应关系是一对一关系,通过外键关联
        publisher = models.ForeignKey(to="Publisher",on_delete=models.CASCADE)
        memo =models.CharField(max_length=128,null=True)
    
    
        def  __str__(self):
            self.title
    

      

  • 相关阅读:
    时间类型:datetime,timestamp,date,time,year
    字符串类型:char,varchar,text,enum,set
    RHEL7安装ZABBIX 3.2
    Go-06-数据类型、常量、运算符
    GO-05-数据类型
    GO-04-变量
    GO-03-基础
    GO-02-helloworld
    Ambassador-09-prefix正则表达式
    Ambassador-08-跨域
  • 原文地址:https://www.cnblogs.com/mainstream/p/11006168.html
Copyright © 2011-2022 走看看