On Sun, Jul 20, 2008 at 11:05 AM, Jon Atkinson <[EMAIL PROTECTED]>
wrote:

> >> > I have no idea what is going on in cases where people have
> >> > admin.autodiscover() in their urls.py yet still get this "You don't
> have
> >> > permission to edit anything" message.  I'd suggest you put a print
> statement
> >> > in django/contrib/admin/__init__.py after the __import__ in
> autodiscover()
> >> > and verify that the auth app, at a minimum, is being found by
> >> > autodiscover(). If not put a print in before the import and ensure
> >> > adutodiscover() is really being called and attempting to import the
> admin
> >> > module for each installed app.
>
> Okay, I've spent a little time on this. There seem to be a few problems.
>
> First of all, I'm a little confused about where to use
> admin.site.register(). A few months ago I checked out the
> newforms-admin branch to try to get a head start, and I followed the
> instructions on this wiki page[1], which recommended importing
> django.contrib.admin at the top of models.py in a given app, then
> registering the models at the bottom of the same file. Of course, I
> realise that the documentation is in flux, but at the time, doing that
> worked.
>
> I've now moved that code into admin.py in my app folder. It looks
> something like this:
>
> -----8<-----
>
> from django.contrib import admin
> from myproj.people.models import Person
>
> class PersonAdmin(admin.ModelAdmin):
>        pass
>
> admin.site.register(Person, PersonAdmin)
>
> -----8<-----
>
> However, when I *also* include admin.autodiscover() in my project-root
> urls.py, the following exception is raised:
>
> ImproperlyConfigured at /admin/
> Error while importing URLconf 'myproj.urls': The model Person is
> already registered
>

It sounds like your admin.py file has already been imported by something
else before the autodiscover() is called.  Did you add an import of your
app's admin into your models.py? That shouldn't be necessary. Also make sure
you don't have an import for it in your __init__.py file; that was the
recommendation when I first migrated to newforms-admin but it led to
multiple registrations like this so was replaced by autodiscover().  You
should not have an explicit import of your app's admin anywhere;
autodiscover() is, I believe, the only thing that should be doing the import
thus ensuring registration is only run once.

Alternatively, you are sure you removed the registration calls from your
models.py file?


>
> If I comment out the contents of my admin.py file, then that exception
> is not raised, and also if I comment out the call to
> admin.autodiscover(), the exception is not raised, however I cannot
> have both active at the same time. A little googling brought up ticket
> 6776 [2], which seems to have been closed, with the introduction of
> admin.autodiscover() as the resolution. I'm not entirely sure what is
> going on there.
>
> Regardless, I took Karen's advice, and modified the __init__.py in
> django.contrib.admin, and added a print statement to see which
> applications were being loaded. In my case, the output was this:
>
> django.contrib.auth
> django.contrib.contenttypes
> django.contrib.sessions
> django.contrib.sites
> django.contrib.admin
> myproj.people
>
> ... which looks reasonable to me (auth is being loaded before admin,
> which would suggest that the permissions would be available to the
> admin app), but I still see the same 'you don't have permission to
> edit anything' message in the admin application.
>

Yes that looks reasonable.  So I'd expect, with that output, that even if
you had removed the registration for your own models, you could go into
admin and edit Users and Sites, for example.


>
> Any help debugging this would be much appreciated - now that
> newforms-admin is in trunk, I can't justify continuing development
> without it, so I'd really like to solve this :-)
>

I'm pretty stumped by this myself.  I can't recreate it (and actually right
now am away from home so unable to even try anything for several hours).
Maybe if you can figure out and solve what is causing the multiple
registration exception that will shed some light....

Karen


>
> --Jon
>
> [1] http://code.djangoproject.com/wiki/NewformsHOWTO
> [2] http://code.djangoproject.com/ticket/6776
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to