Re: inputting a request.user into a model on the backend
On 7 Feb, 22:26, kamilski81 <kamilsk...@gmail.com> wrote:
> I am trying to set a user on a model, on the back-end.
>
> u = request.user
> g = Goal()
> g.user = u
> form = GoalForm(request.POST, g)
>
> I am getting the following error:
> goal.user_id may not be NULL
hello
you can try with this:
if request.method == 'POST':
form = GoalForm(request.POST)
if form.is_valid():
goal=form.save(commit=False)
goal.user=request.user
goal.save()
#AND , if the model as #Many2Many Relationship
form.save_m2m()
I don't know why, but it seems that it is not possible to modify the
data from POST and pass them to a ModelForm constructor, but you need
first pass them to the constuctor, save it, and than modify the handle.
(and again save the m2m table is present).
i hope it 'll help
bye
marcello
--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home