程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

[Django learning notes - 14]: basic use of admin site

編輯:Python

List of articles

  • Localization of management interface
  • Create administrator
  • Register model class
    • 1. Basic registration :admin.site.register( Model class )
      • Configuration of sub applications
      • Modify the name of the model class
      • Change the object name in the model class to the value of the field
    • 2. Use decorators to register
  • Custom administration page

Localization of management interface

  1. Change the web page into Chinese

Create administrator

Input in the terminal :python manage.py createsuperuser

  1. How to retrieve the password

Register model class

1. Basic registration :admin.site.register( Model class )


Configuration of sub applications

Set the name of the sub application project



Modify the name of the model class


Change the object name in the model class to the value of the field



2. Use decorators to register

@admin.register(Wife)
class WifeAdmin(admin.ModelAdmin):
pass
@admin.register(Children)
class ChildrenAdmin(admin.ModelAdmin):
pass
@admin.register(Brother)
class BrotherAdmin(admin.ModelAdmin):
pass
  • After modifying the name of the model class

Custom administration page

#1、 Basic registration 
class HusbandAdmin(admin.ModelAdmin):
# Note that the added fields must be owned in the model class 
list_display = ['name', 'age', 'height', 'wight', 'birthday']
# Set the data entries displayed on each page 
list_per_page = 3
# Adjust the position of the option box 
# Whether the option box is displayed at the top 
actions_on_top = False
# Whether the bottom is displayed 
actions_on_bottom = True
# Search box 
search_fields = ['name', 'age', 'height']
# Filter bar 
list_filter = ['age', 'height']
admin.site.register(Husband, HusbandAdmin)

  • Steps to delete data
  • Add fields




  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved