Hi
I am using both FormMixin, and ListView.
When validating the form I need the users id. How can I get that into the
form for cleaning? I am presuming somehow using get_form and then using the
form's init to grab it, but am unsure of the syntax.
Any ideas?
Many thanks
def post(self, request
For anyone else needing this:
In form:
def __init__(self, *args, **kwargs):
self.creator = kwargs.pop('creator', None)
In view:
form = PostForm(request.POST, creator=self.request.user.pk)
--
You received this message because you are subscribed to the Google Groups
"Django users"
If you're using FormMixin then you can also override get_form_kwargs:
def get_form_kwargs(self):
kwargs = super(MyForm, self).get_form_kwargs()
kwargs['creator'] = self.request.user.pk
return kwargs
Then let FormMixin instantiate the form instance itself.
On Wed, May 13, 2015 at 10:1
Thank you for your reply.
I had previously tried that, but must have had the syntax wrong. Am now
using get_form_kwargs() as it looks nicer.
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving ema
4 matches
Mail list logo