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:
- make a directory named
separated_adminsand put an empty__init__.pyin it -
create files in
separated_adminsdirectory, 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?
The
admin.pyis just a python module. So the right way of splitting it would be as follows:adminsinstead ofadmin.pyfilesome_model_admin.py__init__.pyin theadminsfolder and import * all the files into it.__all__to provide a clean interface.