On Sun, Sep 27, 2009 at 6:55 PM, Michael Williamson <
mikerwilliam...@yahoo.co.uk> wrote:

>
> > A small, recreatable example would help.
>
> I've just recreated by doing the following, all with Django 1.1:
>
>  1. Run django-admin startproject bug
>  2. Set DATABASE_ENGINE to sqlite3 and DATABASE_NAME to /tmp/bug-
> database
>  3. Add 'django.contrib.admin' to INSTALLED_APPS
>  4. Edit urls.py so that it looks like this:
>
> from django.conf.urls.defaults import *
>
> from django.contrib import admin
> admin.autodiscover()
>
> urlpatterns = patterns('',
>     (r'^admin/', include(admin.site.urls)),
> )
>
>   5. Run manage.py startapp blog
>  6. Edit models.py so it looks like this:
>
> from django.db import models
> from django.contrib import admin
>
> class Tag(models.Model):
>    name = models.CharField(max_length=50)
>
> admin.site.register(Tag)
>
>
Ah.  You've put your admin.site.register call in models.py.  This should go
in an admin.py file, not models.py.  Whether your model is registered with
admin is being determined by the accident of whether your models.py file has
happened to be loaded at the time you attempt to access it in admin.  Your
models.py file will have been loaded when running under the development
server, since it does explicit model validation during startup.  Similarly
the admin validation done when DEBUG=True will have ensured that your
models.py file is loaded when you first attempt to access admin.

When running under Apache with DEBUG=False, however, there has not
necessarily been any need to load your models.py by the time you attempt to
access admin. That's why you are getting 404 errors...that call to
admin.site.register has not yet been made.

admin.autodiscover() and placing admin registrations in admin.py files (what
are loaded by admin.autodiscover()) ensures that model registrations happen
once and only once, at a predictable time, regardless of deployment scenario
and debug setting.  If you move your admin registrations to an admin.py file
I believe your problem will go away.

Karen

--~--~---------~--~----~------------~-------~--~----~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to