A model formset gives you multiple instances of the modelform, so you need to iterate through them:
To set the user is basically the same answer as donarb provided. Don't bother with going down to the id level when using a foreign key, just use the object.
So here just use:
readme_form.user = request.user
On Thursday, January 30, 2014 12:02:06 PM UTC-6, Wnt2bsleepin wrote:
-- readme_object = readme_form.save()
readme_object.user = request.user
readme_object.save()
for step_form in step_forms:
for step_form in step_forms:
step_form.readme = readme_object
step_form.save()
To set the user is basically the same answer as donarb provided. Don't bother with going down to the id level when using a foreign key, just use the object.
So here just use:
readme_form.user = request.user
On Thursday, January 30, 2014 12:02:06 PM UTC-6, Wnt2bsleepin wrote:
Didn't seem to work. The step_forms is a modelformset_factory, so I don't know if that makes a difference. I would also like to assign a user to the readme_form, butreadme_form.user_id = request.user.idreadme_object = readme_form.save()step_forms.readme = readme_objectstep_forms.save()doesn't work.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/70c624ab-5cde-4d72-b8c8-6b55d77f5533%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment