On 11 Jan, 04:07, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
>
> 2) I have a model with aUserfield so what I do (on the view) is the
> following:
>
>     Entry.fields['autor'].widget = forms.HiddenInput()
>
>     if request.user.is_authenticated():
>         Entry.fields['autor'].initial = (request.user.id,
> request.user.username)
>
>     So the field doesn't appears but theuseris selected
>     initialy. When the system process the form I get
>
> (Hidden field autor) Enter a list of values.
>

Hi!
Try to set the author-field when you create the form, like this:

form = forms.models.form_for_model ( Entry )

f = form( initial = { 'author': request.user } )

f.base_fields[ 'author' ].widget = forms.HiddenInput()


I'm not sure if this works with user objects in Foreign key fields,
but it works for simpler fields like CharField. If it fails, you could
try to replace

'author'. request.user   with   'author':request.user.id    (?)

/Henrik


--~--~---------~--~----~------------~-------~--~----~
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?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to