On 9/27/06, gkelly <[EMAIL PROTECTED]> wrote:
>
> > The easiest fix I can think of would be to put a hidden field in your
> > form that holds the id of the current user. This will put a 'user'
> > entry into your form data, which will allow the create/update generic
> > views to submit without error.
>
> I definitely do not want to do this for security reasons. Just because
> it's hidden doesn't mean someone can't write a script to POST to my
> page with any user_id they want. And then I ask, what is the point of
> passing the generic view an object_id? Is there a better way to
> approach this problem? My code isn't set in stone, I'm ready and
> willing to learn to do it the right way. It makes sense in my head, but
> Django isn't following the same logic as I.

I think I've worked out the problem you are having.

As it stands, each instance of your UserProfile model will have a
unique 'user' attribute, but it will also have an 'id' attribute
acting as a primary key. This 'id' attribute will has no relationship
with the underlying user id (as no relationship is specified). In
addition, any generic view will expect you to provide a user id
whenever you submit new values. Hence the 'missing user' error
message.

It seems like your assumption is that by making the user attribute
unique=True, it will become the primary key. It doesnt - that keyword
just makes the attribute unique across the table. You can have
multiple unique attributes, if you want to.

You have to specify primary_key=True (instead of unique=True) to make
the attribute a primary key. Once you have done this, the generic
views should work as you expect - with this definition, you are
describing the fact that instances of User are linked to instances of
UserProfile by way of their primary keys, and when you specify an
object_id you are providing detail to populate the user field (since
the object_id _is_ the user id).

Yours,
Russ Magee %-)

--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to