Jason F. McBrayer wrote:
> james_027 <[EMAIL PROTECTED]> writes:
>
> > what if I need additional fields or methods for my apps? Do i inherit
> > it or edit the user class?
>
> The standard approach is here:
> http://www.b-list.org/weblog/2006/06/06/django-tips-extending-user-model

I'm glad this came up, I've been struggling with it myself.  I'd like
to be able to edit the additional fields that I associated with the
User (via my UserProfile class) from the admin interface, right inline
with the rest of the User fields.

So I took the advice in one of the comments in that thread.  I won't
pretend to comprehend it all, but it says:

| class UserProfile(models.Model):
|   user = models.ForeignKey(User, edit_inline=models.TABULAR,
num_in_admin=1,min_num_in_admin=1,
max_num_in_admin=1,num_extra_on_change=0)
|   # ... my additional fields


This produces an error when validating models,

| Validating models...
| keyapp.userprofile: At least one field in UserProfile should have
core=True, because it's being edited inline by user.User.
| 1 error found.


Okay, so who am I to argue with an error message?  I slap a
"core=True," in there with it (on ALL the fields in UserProfile;
anything less causes other problems), and it SEEMS to work!  That is,
there's another box in the admin interface for editing a User object,
with my additional fields available to edit.

Too good to be true, right?
Right. :-(
I can neither add a UserProfile nor edit the values of the UserProfile
from the User-edit admin page.

I know, I know, it was unreasonable to expect it to be THAT easy.  But
the fact that it DISPLAYS the fields from another table (and
*pretends* to let me edit them even though it discards my changes)
with so little work on my part makes me think it might work if I
wasn't doing something wrong or dumb.

/myproj/mainweb/settings.py:
|  INSTALLED_APPS = (
|    'django.contrib.auth',
|    'django.contrib.contenttypes',
|    'django.contrib.sessions',
|    'django.contrib.sites',
|    'myproj.mainweb.myweb.myapp',  # my stuff
|    'django.contrib.admin',    # user-account administration interface
(provided by Django)
|  )
|  AUTH_PROFILE_MODULE = 'myapp.UserProfile'


/myproj/mainweb/myweb/myapp/models.py:
|  from django.db import models
|  from django.contrib.auth.models import User
|  class UserProfile(models.Model):
|    user = models.ForeignKey(User, edit_inline=models.TABULAR,
num_in_admin=1,min_num_in_admin=1,
max_num_in_admin=1,num_extra_on_change=0, core=True)
|    ftv = models.CharField('Favorite TV Station', maxlength=4,
core=True)
|    phone = models.CharField('Telephone Number', maxlength=24,
core=True)
|  class Admin:
|    pass

The UserProfile fields DO show up in the User-editing admin page, as
input fields... but any input or changes to them are ignored/discarded.


--~--~---------~--~----~------------~-------~--~----~
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