среда, 18 декабря 2019 г., 19:46:18 UTC+3 пользователь Adam Johnson написал:
>
> Hi Vladimir
>
> Posting code to this mailing list is the wrong way to try make 
> contributions. Thanks for offering though.
>
> Please read the guides at 
> https://docs.djangoproject.com/en/dev/internals/contributing/ for how to 
> post tickets and code.
>
> However from a quick skim I'm not sure your code is valuable to add to 
> Django core at this time.
>
> Thanks,
>
> Adam
>
> On Wed, 18 Dec 2019 at 14:31, Vladimir Godovalov <[email protected] 
> <javascript:>> wrote:
>
>> 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 [email protected] <javascript:>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-developers/1fddfa20-339f-463a-a168-e86d8bb3f739%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-developers/1fddfa20-339f-463a-a168-e86d8bb3f739%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>
>
> -- 
> Adam
>
 
 

Thanks Adam, I will do it the right way.

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/1fa518ec-36f4-4963-b82e-5908ee6b5d2e%40googlegroups.com.

Reply via email to