Where admin classes should be registered ?

29 views
Skip to first unread message

Alireza Savand

unread,
Jun 27, 2012, 3:54:07 AM6/27/12
to django...@googlegroups.com
Hi
Common way to create [model|admin] classes is implement and create them in [models|admin].py file.
But as standard non-django way is to create a python package named admin for AdminClass es and  create a file for each admin class.
But i couldn't find any standard way to register those admin classes, i mean should i register them in admin/__init__.py or register each class in it own file then import them at admin/__init__.py ?
Sometimes when i register all of them at admin/__init__.py it's happening that classes will initialed multiple times and i don't know the reason.
I'm just looking for common or standard way to do it.

Thanks.

Matt Schinckel

unread,
Jun 27, 2012, 6:54:07 AM6/27/12
to django...@googlegroups.com
I generally register admin models where I define them, and then just import that
file in admin/__init__.py

If you are getting multiple registration errors, it may be that your app appears
twice in sys.path (perhaps as app, and project.app?).

That's generally a Bad Thing(tm).

Matt.

Alireza Savand

unread,
Jun 27, 2012, 7:00:37 AM6/27/12
to django...@googlegroups.com
As your approach, at admin/__init__.py i have to

from myapp.admin.ouradmin import *

That means import all of the classes inside that files.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/VXzngj1e75sJ.

To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Daniel Roseman

unread,
Jun 27, 2012, 10:28:05 AM6/27/12
to django...@googlegroups.com
There is absolutely a standard way to do this, which is fully documented.

Define all your ModelAdmin classes in an admin.py inside each app. Register the classes in that file (usually together at the end). In your main urls.py, call `admin.autodiscover()`, which imports all the admin.py files which causes them to be registered.

If you do anything else, you may well run into multiple registration problems. Don't. Follow the standard.
--
DR.

Alireza Savand

unread,
Jun 28, 2012, 2:26:05 AM6/28/12
to django...@googlegroups.com
Yes, But when my models.py/admin.py reach to +2000 line then django standard way not gonna help. That's why i seperate the classes into files and pkgs.
I'm wonder is there any performance issue on this approach, since each class is in separate file, when i import them i'm sure python should find them at the filesystem and initial them or they will be initialized by django ?


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/h2g8jTwkmrAJ.

Shane Shane Bichel

unread,
Jun 28, 2012, 2:35:28 AM6/28/12
to django...@googlegroups.com
jjcjgxydhfxydzh

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/_UjokPA1WgYJ.
Reply all
Reply to author
Forward
0 new messages