Please write to django-users, this mailing list is for the development of 
Django itself.

On Wednesday, October 14, 2015 at 2:50:56 AM UTC-7, Ernest Appiah wrote:
>
>
>
>
> I have a Django form and l would like to pass a user instance when the 
> form is created
>
> *First Approach*
>
> This is where l create the form and pass the instance of the user:
>
> form = QuestionForm(request.user, request.POST)
>
> And inside the QuestionForm
>
> def __init__(self, user, *args, **kwargs):
>     super(QuestionForm, self).__init__(*args, **kwargs)
>     self.data = user
>     log.info(self)
> Study.objects.filter(owner = self.data.id))
>
> *Second Approach* This is where l create the form and pass the request:
>
> form = QuestionForm ( ..., request=request)
>
> And inside the QuestionForm
>
> def __init__(self, *args, **kwargs):
>     self.request = kwargs.pop("request")
>     super(MyForm, self).__init__(*args, **kwargs)
> Study.objects.filter(owner = self.request.user.id))
>
> Now l am getting an error that self is not define and as such l cannot get 
> the user id to query the Study class
>
> Any help would be much appreciated
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/82d909fb-8f50-49fa-8201-9b57afb4158c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to