I'm trying to split admin.py
of a Django project into separate files but failed.
There's no information I can find from google about how to split it, so I have to try myself. Here's what I tried:
separated_admins
and put an empty __init__.py
in itcreate files in separated_admins
directory, something like this:
# file my_app/seperated_admins/Some_Model_admin.py
from my_app.models import Some_Model
from django.contrib import admin
admin.site.register(Some_Model)
in admin.py
, I added lines like:
from my_app.seperated_admins import *
But I didn't see Some_Model
in my admin site. Is my solution right? How can I fix this?
To change the admin site header text, login page, and the HTML title tag of our bookstore's instead, add the following code in urls.py . The site_header changes the Django administration text which appears on the login page and the admin site. The site_title changes the text added to the <title> of every admin page.
your company should follow a least access principle policy; so yes: only select people should have access. Django has basic auditing capability via signals and displayed in the admin out of the box. You can build on top of this.
You can add another class called Meta in your model to specify plural display name. For example, if the model's name is Category , the admin displays Categorys , but by adding the Meta class, we can change it to Categories . Literally saved my life!
The admin
is just a python module. So the right way of splitting it would be as follows:
admin
instead of admin.py
Some_Model_admin.py
__init__.py
in the admin
folder and import * all the files into it.__all__
to provide a clean interface.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With