heya,
I'm having issues extending Django's user model via UserProfile, and
then editing this through the admin interface. Essentially, what I
want is to add some extra fields to the User model (I've called this
model "Person"), and be able to edit these along with the normal User
attributes inline all from a single page.
In models.py:
from django.db import models
from django.contrib.auth.models import User
...
class Person(models.Model):
user = models.ForeignKey(User, unique=True)
has_paid = models.BooleanField()
In admin.py:
from django.contrib import admin
from django.contrib.auth.models import User
from django.contrib.auth.admin import UserAdmin
from people.models import Person, Department
class PersonInline(admin.StackedInline):
model = Person
class UserAdmin(admin.UserAdmin):
inlines = [PersonInline]
class DepartmentAdmin(admin.ModelAdmin):
pass
admin.site.register(Department, DepartmentAdmin)
admin.site.unregister(User)
admin.site.register(User, UserAdmin)
I've also added this to settings.py:
AUTH_PROFILE_MODULE = 'people.Person'
Sometimes, it seemed to come up with error message "AttributeError at /
admin/auth/user/1/
'module' object has no attribute 'UserAdmin'". The weird thing was,
this seemed to be intermittent, and a refresh of the page loaded up
the admin interface normally. However, when that did load, the editing
links for Department and Person didn't appear in admin, and nor was
there anything about the extra fields under User. There was just the
"Auth" and "Sites" section.
Anyhow, what's the best way of achieve what I want (basically
seamlessly combining User/Person, so it'd appear as if User just had
some extra fields).
Cheers,
Victor
PS: I've read a tonne of sites, some of which seem to say slightly
different things:
One page (http://sam.bluwiki.com/blog/2008/05/extending-user-model-
profiles-in-django.php), recommended using something like:
user = models.ForeignKey(User, unique=True,
edit_inline=models.TABULAR, num_in_admin=1,min_num_in_admin=1,
max_num_in_admin=1,num_extra_on_change=0)
However, this caused an error at models.TABULAR on my end.
Other sites:
http://pyxx.org/2008/08/18/how-to-extend-user-model-in-django-and-enable-new-fields-in-newforms-admin/
http://www.thenestedfloat.com/articles/displaying-custom-user-profile-fields-in-djangos-admin
http://www.amitu.com/blog/2007/july/django-extending-user-model/
http://www.codekoala.com/blog/2009/quick-django-tip-user-profiles/
http://www.b-list.org/weblog/2006/jun/06/django-tips-extending-user-model/
http://shityoucantremember.wordpress.com/2009/02/14/unriddling-the-django-user-profile/
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
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.