On Aug 6, 2:24 am, Julián C. Pérez <jcp...@gmail.com> wrote:
> Hi everyone
> I'm in trouble because of a form class
> I have a form class with attributes defined, but with one thing:
> One of the attributes requires the current user, or al least its
> username
>
> The form definition in as shown below:
> ---
> class SendMessageForm(forms.Form):
>         recipientUser = ShowValidContactList(label=u'Send to')
>         messageSubject= forms.CharField(label=u'Subject')
>         messageContent = forms.CharField(label=u'Content',
> widget=forms.Textarea())
> ---
>
> As you can tell I'm trying to make a 'Send message' form to make
> message sending available in my project... but the recipient user must
> be in the contacts list of the current user...
> The 'recipientUser' field is a ShowValidContactList
> (forms.ModelChoiceField) instance... so it works with a fixed queryset
> based on that user (the currently logged-in one)
>
> My problem is that... how can I get the current user information
> outside a view and without request objects??
> Or... how can I make that form works with a different approach??
>
> Any help would be appreciate!

This is asked frequently on this group. The answer is to override the
form's __init__ method and pass the request in there, and store it on
a form attribute for later use.
--
DR.
--~--~---------~--~----~------------~-------~--~----~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to