Hi
I tried doing that...
But it does not work
For example, if I do something like...
---
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())
        def __init__(self, currentUser):
                self.currentUser = currentUser
                super(SendMessageForm, self).__init__(*args, **kwargs)
---
that init method in my custom form class won't change anything in the
already defined ShowValidContactList field

I also tried threadlocal's approach... but it didn't work either and
it's a weird way to do that...
I'm gonna go in a different direction, inspired by similar former
problem
Thank you alll, now I'll report with my status

On Aug 6, 1:40 am, Daniel Roseman <dan...@roseman.org.uk> wrote:
> 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