入门3:后台管理

创建用户:

python manage.py createsuperuser
image.png
怎么把我们的app放到管理员界面进行管理?

在polls/admin.py文件中进行修改。

from django.contrib import admin
from .models import Question
# Register your models here.
admin.site.register(Question)
image.png
点进去一看:
image.png
发现polls下有了Question这个对象:
image.png
from django.db import models
# Create your models here.
class Question(models.Model):
    #Create char type attribute in DB, which length is 200,name is question_text.
    question_text = models.CharField(max_length=200)
    #Create time type attribute in DB, which name is pub_date
    pub_date = models.DateTimeField('date published')
image.png
把polls/models.py中pub_date = models.DateTimeField('date published')的'date published'删除得到pub date。
image.png
查看history可得:
image.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容