Reputation: 31568
I have many apps and i want to activate the admin for all the models in my all apps.
I remember few months one of my friend did something that enables the admin site without any admin.py file
he did something in settings.py
files with INSTALLED_APPS
and all of the apps showed in the admin section
I am now not able to find that. Any one??
Upvotes: 0
Views: 277
Reputation: 12478
I recommend you do include an admin.py
in your apps because it is the Django convention and that some explicitness in what you trying to achieve is a good thing; the solution I use is the following default admin.py
template for all new apps I start:
# Auto registers any new models with the admin, eventually you will want a tailored admin.py
from django.contrib import admin
current_app = models.get_app(__package__)
for model in models.get_models(current_app):
admin.site.register(model, admin.ModelAdmin)
Upvotes: 0
Reputation: 118498
Your friend probably did something like...
from django.db.models import get_models
for model in get_models():
admin.site.register(model)
In one of his admin.py files.
I dunno, I'd only do this to test stuff. It's a bit too magical. Remember you'll have to explicitly unregister
any models you may want to register again.
Upvotes: 1
Reputation: 25609
Just follow the instructions in the docs. They describe how to activate the django admin site here. You need to modify urls.py
. That's it.
There are even comments in that file that tell you which three lines to uncomment.
Upvotes: 1