zoukankan      html  css  js  c++  java
  • 10 基类

    基类

    基类是抽象的类(不会完成数据库迁移),数据库中不会存在该表,目的是提供共有字段的

    class BaseModel(models.Model):
        is_delete = models.BooleanField(default=False)
        updated_time = models.DateTimeField(auto_now_add=True)
     
        class Meta:
            abstract = True  # 必须完成该配置
    

    应用

     
    class Book(BaseModel):
        name = models.CharField(max_length=64)
        price = models.DecimalField(max_digits=5, decimal_places=2, null=True)
        image = models.ImageField(upload_to='img', default='img/default.png')
     
        publish = models.ForeignKey(to='Publish', related_name='books', db_constraint=False, on_delete=models.DO_NOTHING)
        authors = models.ManyToManyField(to='Author', related_name='books', db_constraint=False)
     
     
    class Publish(BaseModel):
        name = models.CharField(max_length=64)
     
     
    class Author(BaseModel):
        name = models.CharField(max_length=64)
     
     
    class AuthorDetail(BaseModel):
        phone = models.CharField(max_length=11)
        author = models.OneToOneField(
            to=Author,
            related_name='detail',
            db_constraint=False,
            on_delete=models.SET_NULL,
            null=True
        )
    
  • 相关阅读:
    常见字体图标库——font-awesome
    windows server 2012显示桌面图标
    SE 2014年4月14日
    SE 2014年4月13日
    PPP协议总结
    SE 2014年4月12日
    django运行时报错
    linux-python在vim下的自动补全功能
    python发邮件
    背景透明兼容
  • 原文地址:https://www.cnblogs.com/cnhyk/p/12459071.html
Copyright © 2011-2022 走看看