+ Django hands-entry Pycharm combat tutorial 5- admin page

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/baidu_39459954/article/details/90440852

Django administration page (admin) Profile

For your employees or customers generate a user to add, modify, and delete the contents of the background is a lack of creativity and tedious work. Therefore, Django fully automatically create backend interfaces according to the model. Django produced in the process of developing a public page and content publishers to completely separate pages of news sites. Site managers use the management system to add news, sports events and newsletters, etc. These added content is displayed on the public page. Django solves this problem by creating a unified content editing interface for the site managers. Management interface is not for site visitors, but for managers to prepare.

Create an administrator account

python manage.py createsuperuser

Here Insert Picture Description

Enter the site management page

Start the development server

python manage.py runserver

Open your browser, go to your local domain name "/ admin /" directory, such as " http://127.0.0.1:8000/admin/ ." You should see the Administrator login screen:
Here Insert Picture Description
super user you created in the previous step to log in. Then you will see the Django admin index page page:
Here Insert Picture Description
you will see several editable content: groups and users. They are provided by django.contrib.auth, which is authentication framework Django development.

Added to the voting application management page

But voting application we created is not displayed in the index page. Just do one thing: we have to tell management page, the problem Question objects need to be managed. Open the polls / admin.py file, edit it to this:

from django.contrib import admin

# Register your models here.
from .models import Question

admin.site.register(Question)

现在我们向管理页面注册了问题 Question 类。Django 知道它应该被显示在索引页里:
Here Insert Picture Description
点击 “Questions” 。现在看到是问题 “Questions” 对象的列表 。这个界面会显示所有数据库里的问题 Question 对象,你可以选择一个来修改。这里现在有我们在上一篇中通过API创建的 “What’s up?” 问题。
Here Insert Picture Description
点击 “What’s up?” 可以编辑这个问题(Question)对象:
Here Insert Picture Description
注意事项:

  • 这个表单是从问题 Question 模型中自动生成的
  • 不同的字段类型(日期时间字段 DateTimeField 、字符字段CharField)会生成对应的 HTML 输入控件。每个类型的字段都知道它们该如何在管理页面里显示自己。
  • 每个日期时间字段DateTimeField 都有 JavaScript写的快捷按钮。日期有转到今天(Today)的快捷按钮和一个弹出式日历界面。时间有设为现在(Now)的快捷按钮和一个列出常用时间的方便的弹出式列表。

页面的底部提供了几个选项:

  • 保存(Save) - 保存改变,然后返回对象列表。
  • 保存并继续编辑(Save and continue editing) -保存改变,然后重新载入当前对象的修改界面。
  • 保存并增加另一个(Save and add another) -保存改变,然后添加一个新的空对象并载入修改界面。
  • 删除(Delete)- 显示一个确认删除页面。

如果显示的 “发布日期(Date Published)” 和你在教程4 里创建它们的时间不一致,这意味着你可能没有正确的设置 TIME_ZONE 。改变设置,然后重新载入页面看看是否显示了正确的值。

By clicking on the "Today (Today)" and "now (Now)" button to change the "release date (Date Published)". Then click "Save and continue editing (Save and add another)" button. Then click on the top right corner of the "History (History)" button. You will see a list of all the current page objects by changing the Django admin page, which lists the time stamps and modify operations Username:
Here Insert Picture Description

Guess you like

Origin blog.csdn.net/baidu_39459954/article/details/90440852