Migrating to newforms-admin and classes already registered error

111 views
Skip to first unread message

Peter Bailey

unread,
Jul 22, 2008, 3:21:42 PM7/22/08
to Django users
Hi all. I am attempting to convert an app I am writing to use the nfa.
I have looked at all the docs available about this, but must have
missed something. I am using:

Django version 1.0-alpha-SVN-8053

Anyway, I have changed my urls.py file to be like so:

from django.contrib import admin

(r'^admin/(.*)', admin.site.root), # in urlpatterns

and in my models file I have:

from django.contrib import admin

and then after my Page class declaration I have

admin.site.register(Page)

which creates the following error at runtime:

ImproperlyConfigured at /
Error while importing URLconf 'generator.urls': The model Page is
already registered

I have tried using the autodiscover and not using it - same result - I
also see some people are using an admin.py file and some are just
modifying the model.py file.

Can anyone point me at some info or tell me what I am doing wrong.
Feeling kinda stupid about now...

Thanks,

Peter


Malcolm Tredinnick

unread,
Jul 22, 2008, 3:23:51 PM7/22/08
to django...@googlegroups.com

The recommended approach (and the reason for autodiscover()) is to put
the admin classes and registration into admin.py. Your models.py files
are imported more than once, which is leading to the duplicate
registration error (which is a real error in other situations, which is
why it exists).

Putting things in admin.py is a way to make sure they're only registered
once.

Regards,
Malcolm


Peter Bailey

unread,
Jul 22, 2008, 4:01:27 PM7/22/08
to Django users
That works much better Malcolm, thank you very much. Appreciate the
explanations too.

Cheers,

Peter


On Jul 22, 3:23 pm, Malcolm Tredinnick <malc...@pointy-stick.com>
wrote:

Hernán Olivera

unread,
Jul 29, 2008, 7:31:10 PM7/29/08
to Django users
You must register once. Delete the admin classes from the models.
Reply all
Reply to author
Forward
0 new messages