The Django Admin is a component for adding and checking the corresponding data tables in the model, and the registered model tables under each app are added and censored. The stark component is modeled after the admin component.
Common configuration of admin:
Filedstes
Use methods and effects such as
Action
Methods of Use and
Need to be in my_appconfig (admin. modeadmin) write custom functions in
Note: (1) This function is used as value in the Select drop-down box
(2) The function has two parameters, namely request, Queryset
(3) Front-end check box, front-end integration into a dictionary. Dictionary key: The name of the check box, the value of the dictionary: list type, storage Valu
The defined foo will be in the Selec t drop-down box of the front action, and the function name as value
Click Go, according to the Select drop-down boxValue, values,Just now.name of the function definedSend back end, back end get this value, find this function and execute.
Admin uses two scenarios:
1) Admin Config URL
2) Register model
Note: There is an admin module under each app
Use process
1. When the Django project starts, the Admin app first scans (loads) each admin.py file under each app
Self-executing function, Autodiscover () performs a scan, scans
2, each admin file Import Admin module, generate site object,
Attention:admin.site.registry (book), when registering, _registry{} The key saved by the dictionary is the class name in model, and the value is the Adminclass class of the model's management class
3. Use the Site object to register the class name in model
4, create the registered model class additions and deletions to change the URL
Knowledge Points:
1, the same module repeated calls, the file is only loaded once
2, module-based singleton mode, the first time the object is generated, will generate a memory space _instance, when the second generation, _instance has a value, the memory of the object will be pointed to the memory space of the previous object
Routing distribution
A URL consists of a regular and a corresponding function, and routing is the transformation of a function into a tuple. Tuples include a list, and two none values
In the process of the admin development, the purpose is to generate the model corresponding URL, need to get the name of the app and mode name of the model.
Using My_model._meta.model_name to get
Customizing the Stark component as admin: Note that in the stark apps.py configuration file, add a function to the class
def Ready (self): autodiscover_modules ("stark_admin")
The meaning of the function:--Execute the Read method under the file--Scan the STARTK file
Note: Static is placed under the project, you need to configure staticfiles under the application, no need to configure. Django scans for static files under each item
Request requests: The requested URL, which can be used with request. Get Get Data
2.
Python Stark components