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))

 

posted @ 2018-11-14 20:58  Niuli'blog  阅读(613)  评论(0编辑  收藏  举报