models.py
from django.dbimport models
class Publisher(models.Model):
name = models.CharField(max_length=32,verbose_name="出版社")
class Meta:
verbose_name ='出版社'
verbose_name_plural = verbose_name
def __str__(self):
return self.name
class Book(models.Model):
title = models.CharField(max_length=32,verbose_name="书名")
pub = models.ForeignKey(Publisher,on_delete=True,verbose_name="出版社外键")
class Meta:
verbose_name ='书籍'
verbose_name_plural = verbose_name
admin.py
from django . contribimport admin
from . models import Publisher,Book
@admin . register(Publisher)
class PublisherModel(admin.ModelAdmin):
list_display = ["name"]
@admin . register(Book)
class BookModel(admin.ModelAdmin):
list_display = ["title","pub"]
apps.py
from django.appsimport AppConfig
class IndexConfig(AppConfig):
name ='index'
verbose_name ='书刊管理'
settings.py
INSTALLED_APPS = [
'simpleui',没有这个模板的可进行安装pip install simpleui
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'index.apps.IndexConfig',
]
DATABASES = {
'default': {
'ENGINE':'django.db.backends.mysql',
'HOST':'127.0.0.1',
'PORT':'3306',
'NAME':'waijian',
'USER':'root',
'PASSWORD':'qwe123',
}
}
LANGUAGE_CODE ='zh-hans'
TIME_ZONE ='Asia/Shanghai'
网友评论