zoukankan      html  css  js  c++  java
  • django admin登陆添加修改内容

    model文件中 

    __all__ = ["Book", "Publisher", "Author"]
    from django.db import models
    
    # Create your models here.
    __all__ = ["Book", "Publisher", "Author"]
    
    
    class Book(models.Model):
        title = models.CharField(max_length=32)
        CHOICES = ((1, "Python"), (2, "Linux"), (3, "go"))
        category = models.IntegerField(choices=CHOICES)
        pub_time = models.DateField()
        publisher = models.ForeignKey(to="Publisher")
        authors = models.ManyToManyField(to="Author")
    
        def __str__(self):
            return self.title
    
    
    class Publisher(models.Model):
        title = models.CharField(max_length=32)
    
        def __str__(self):
            return self.title
    
    
    class Author(models.Model):
        name = models.CharField(max_length=32)
    
        def __str__(self):
            return self.name

    admin文件中

    from django.contrib import admin
    from . import models
    
    # Register your models here.
    
    for table in models.__all__:
        admin.site.register(getattr(models, table))
  • 相关阅读:
    题目1101:计算表达式
    九度oj 题目1107:搬水果
    [Hihocoder] 字符串排序
    [hzwer] 模拟T
    [Luogu] 宝藏
    [Luogu] 列队
    [Luogu] 奶酪
    [Luogu] 逛公园
    [Luogu] 时间复杂度
    [Luogu] 小凯的疑惑
  • 原文地址:https://www.cnblogs.com/niuli1987/p/9960319.html
Copyright © 2011-2022 走看看