Hi again.
Maybe this has been discussed before (please tell me).
In each and every Django project I start, I need the Django Admin during
development to create some model data for testing.
And each and every time I wonder why I have to add the same boilerplate
code for every single model in every app.
So in most projects, I start with a generic way of adding all models to
admin.py programmatically.
and after a few iterations, I thought I'll ask you if that wasn't a
helpful default to add to Django itself.
* I know that there are ModelAdmins, in case you want to sort it out
differently
* I know that there are edge cases and abstract models that shouldn't be
listed
So what if Django (admin) would add models to the admin view, if
* DEBUG==True,
* maybe another attr is present, like settings.AUTO_ADMIN_MODELS
* all admin.py files are already parsed and manually added models are
included, with their special ModelAdmins
like:
# first parse all apps' admin.py
if settings.DEBUG:
# all other models
models = apps.get_models()
for model in models:
try:
if not model._meta.abstract:
admin.site.register(model)
except admin.sites.AlreadyRegistered:
pass
It would help getting started with Django more quickly.
--
Dr. Christian González
https://nerdocs.at