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))
原文地址:https://www.cnblogs.com/niuli1987/p/9960319.html