13

I have m2m field, lets say it have name 'relations', so i want to allow user to send as many relations as he wants. I add new input to html with javascript with same name, like so

<input type='text' name='relations' value='a' />
<input type='text' name='relations' value='b' />

in cleaned_data i receive only value of second input ('b'). How to receive both?

3 Answers 3

29

I don't know how to do that with Forms, but if you want to grab the values in the raw way, here's how I'd do:

relations = request.POST.getlist('relations')
Sign up to request clarification or add additional context in comments.

Comments

5

You don't need to grab all the raw values, you can just get the specific data by using element name like this:

relations = request.form.getlist('relations')

That will return a list of values in the relations input.

1 Comment

There's no 'request.form' in Django 1.9.
1

this generate a list, you can manipulate in for

request.POST.getlist('relations')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.