L
L
Lopus2016-04-16 16:31:33
Django
Lopus, 2016-04-16 16:31:33

How to set HiddenInput value?

There is a model with posts and comments. Comments are linked to the post via foreignkey. respectively the post field.
I made a form from ModelForm, specified fields post, fio, body
.
In the view, I declare the worm like this:


post = get_object_or_404(Post, id=id)
form = AddComment()
return render(request, 'blog/detail.html', {'post': post, 'form': form})

Tried like this:

form.post = post

but doesn't work :)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lopus, 2016-04-16
@Lopus

Understood:
form = AddComment(initial={'post': post})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question