heya,

I should probably add an example - we want to add a Title field to the
user form. Ideally, this would appear seamlessly as part of the User
form, next to the name fields, rather than it's own separate sub-
section below. What would be a Django-esque way of achieving that?

Cheers,
Victor

On Dec 9, 3:24 pm, Victor Hooi <[email protected]> wrote:
> heya,
>
> Well, now that was a bit silly of me.
>
> I just noticed that I was importing with "from
> django.contrib.auth.admin import UserAdmin", but then I was calling
> "admin.UserAdmin" below, rather than "UserAdmin". I've fixed that now,
> and the "People" app is now appearing in the admin interface. I'm
> still a bit confused as to why it sometimes seemed to load before, and
> sometimes gave the unable to find UserAdmin error before.
>
> Anyhow, on the User editing form, it does indeed have the extra
> "Person" attributes at the bottom (in this case, just "has_paid").
>
> However, each Department has a Head, which is a FK to a Person/User in
> the database. Initially, the drop-down list to select a Head is empty
> (I guess we have no Person objects). However, if I edit a user, and
> toggle the has_paid field, it will create the Person object associated
> with that user. Then, if I go into Department, the drop down now has
> "Person object" in it. I suppose I can edit the __unicode__ method for
> Person to spit out something a little friendlier (that's the best
> thing to do, right?)
>
> Either way, is there a friendlier way of auto-creating those Person
> objects, whenever a user is added? Or more tightly binding those two
> objects, User/Person together? All I really want is to add some extra
> fields to User - and I know that Bennett's blog post lists several
> reasons why a user-profile is better than sub-classing User, so I
> guess profiles is the way to go, but I'm trying to find a more
> intuitive way to deal with it all.
>
> Cheers,
> Victor
>
> On Dec 9, 2:53 pm, Victor Hooi <[email protected]> wrote:
>
>
>
> > 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-ena......

--

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.


Reply via email to