Hello to everyone,
# This non-trivial patch improve Django functionality
# by providing automatic registration in main admin.py
# of all admin files of the project
#### admin.py module code ####
# admin.py
import importlib
from django.contrib import admin
from django.apps import apps
# automatic registration module
models = apps.get_models()
for model in models:
model_name =
str(model.__name__)
# import and registration
app_list =
model.__module__.split(".")
idx = app_list.index('models')
app1 = app_list[idx-1]
del app_list[idx:]
try:
module =
importlib.import_module('.'.join(app_list)+'.'+app1.title()+'Admin')
except ImportError:
continue
class_admin =
module.str_to_class(model_name+'Admin')
if class_admin is None:
continue
try:
admin.site.register(model,
class_admin)
except
admin.sites.AlreadyRegistered:
pass
### an application admin module
code ###
# make sure the module name looks like 'BaseAdmin.py',
# where the module name begins with the application
# name in uppercase as well as the word 'Admin'
# BaseAdmin.py
import sys
....
insert your code here
....
def str_to_class(str):
try:
obj =
getattr(sys.modules[__name__], str)
except AttributeError:
return None
return obj
--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/1fddfa20-339f-463a-a168-e86d8bb3f739%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to django-d...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/1fddfa20-339f-463a-a168-e86d8bb3f739%40googlegroups.com.
--Adam
Thanks Adam, I will do it the right way.