Django + user profile admin inlines = breakage

8 views
Skip to first unread message

hagan

unread,
Jul 1, 2009, 7:51:38 PM7/1/09
to Django users
I'm using python 2.6.2, django 1.1-beta-1 with mod_wsgi 2.5.... So
this very well could be a beta bug...

I'm having a strange problem, which I've tracked down to my
UserProfile model... well, the admin interface.

Basically I'm trying to do something like this.... (Simplified from
working model)

-----------------------models.py----------------------------
from datetime import datetime
from django.db import models
from django.contrib.auth.models import User
from django.contrib.auth.admin import UserAdmin

class UserProfile(models.Model):
someinfo = models.CharField(max_length=128)

def __unicode__(self):
return self.someinfo

class SomeModel(models.Model):
date = models.DateField()

@property
def due_date(self):
return datetime.today()

admin.site.unregister(User)
class UserProfileInline(admin.StackedInline):
model=UserProfile

class UserProfileAdmin(UserAdmin):
inlines = [ UserProfileInline ]


admin.site.register(User, UserProfileAdmin) #<====== That results
in errors....

------------------------/
models.py---------------------------------------

So, I can get UserProfile included in the UserAdmin page.. That works,
however every time I load the wsgi thread I get an error:

"The model User is not registered"

And on the 2nd page refesh, that error goes away. I had chalked that
up as an annoyance up until it became obvious something with my inline
is causing issues with datetime.today() as well.

Without the admin.site.register override datetime.today() works...
With it I get:

Exception Value: 'NoneType' object has no attribute 'today'
Exception Location: /home/webby/add/dilettante/models.py in due_date,
line 120

I'm hoping someone else has seen this error or recognizes that i've
done something obviously wrong.

hagan

unread,
Jul 2, 2009, 2:50:19 PM7/2/09
to Django users
Ah, got this working.... It helps to put admin stuff in the admin.py
file. I was doing to much in the models.py file and after spending a
moment to separate admin/model/forms everything started to work
magically... Possibly because I added "admin.autodiscover()"....
Reply all
Reply to author
Forward
0 new messages