Issue
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_admins
and put an empty__init__.py
in it create 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?
Solution
The admin.py
is just a python module. So the right way of splitting it would be as follows:
- Create a folder called
admins
instead ofadmin.py
file - Use multiple files within the admin folder, like your
some_model_admin.py
- Create a
__init__.py
in theadmins
folder and import * all the files into it. - You might also want to include an
__all__
to provide a clean interface.
Answered By - lprsd
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.