Discussion:
Make a loop to get request.POST information
Thibaud MONTAGNON
2018-11-26 16:13:01 UTC
Permalink
Hi,

I got 3 differents input named input_1, input_2, input_3 and I want to make
a loop to put them in the ddb.

I try to use this code but it dosent work...

row=[1,2,3]

for a in row:
polls = Polls.objects.create(motsclef=request.POST[*'input_'.a*])

Could you help me ?

(I just want to simplify this :

polls = Polls.objects.create(motsclef=request.POST[*'input_1'*])
polls = Polls.objects.create(motsclef=request.POST[*'input_2'*])
polls = Polls.objects.create(motsclef=request.POST[*'input_3'*])
)
--
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+***@googlegroups.com.
To post to this group, send email to django-***@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f87e75b6-a8ec-4ff1-b0ea-3fc49529bbb5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
shiva kumar
2018-11-26 16:25:05 UTC
Permalink
Try this
Replace 'input_'.a with
'input_'+str(a)

I think it will work
Post by Thibaud MONTAGNON
Hi,
I got 3 differents input named input_1, input_2, input_3 and I want to
make a loop to put them in the ddb.
I try to use this code but it dosent work...
row=[1,2,3]
polls = Polls.objects.create(motsclef=request.POST[*'input_'.a*])
Could you help me ?
polls = Polls.objects.create(motsclef=request.POST[*'input_1'*])
polls = Polls.objects.create(motsclef=request.POST[*'input_2'*])
polls = Polls.objects.create(motsclef=request.POST[*'input_3'*])
)
--
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
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/f87e75b6-a8ec-4ff1-b0ea-3fc49529bbb5%40googlegroups.com
<https://groups.google.com/d/msgid/django-users/f87e75b6-a8ec-4ff1-b0ea-3fc49529bbb5%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
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+***@googlegroups.com.
To post to this group, send email to django-***@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAMsYeuGtBZvmiFbUgOhnFSm0XjkJbxaFNPNLanbQ0wnjUQ9rRA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Thibaud MONTAGNON
2018-11-26 16:58:55 UTC
Permalink
It's work ! Thanks :)
--
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+***@googlegroups.com.
To post to this group, send email to django-***@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/cd331cb6-6f14-4be4-a74f-acd44c6cb7d1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
kennedy kay
2018-11-26 16:52:01 UTC
Permalink
This should work

##method 1
Polls = []
#then create a list of poll objects and append to the polls list
Polls.append('input_'+str(x))
Hi,
I got 3 differents input named input_1, input_2, input_3 and I want to
make a loop to put them in the ddb.
I try to use this code but it dosent work...
row=[1,2,3]
polls = Polls.objects.create(motsclef=request.POST[*'input_'.a*])
Could you help me ?
polls = Polls.objects.create(motsclef=request.POST[*'input_1'*])
polls = Polls.objects.create(motsclef=request.POST[*'input_2'*])
polls = Polls.objects.create(motsclef=request.POST[*'input_3'*])
)
--
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+***@googlegroups.com.
To post to this group, send email to django-***@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/065486e2-8c04-4ce7-920c-956f5ca610ce%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
kennedy kay
2018-11-26 16:49:54 UTC
Permalink
Or you can simply do something like this

##method 1
Polls = []
#then creat a list of poll objects and append to the polls list
Polls.append('input_'+str(x))
polls = Polls.object.create(motsclef = request.POST['input_{x}' for x in
range(3)])
Hi,
I got 3 differents input named input_1, input_2, input_3 and I want to
make a loop to put them in the ddb.
I try to use this code but it dosent work...
row=[1,2,3]
polls = Polls.objects.create(motsclef=request.POST[*'input_'.a*])
Could you help me ?
polls = Polls.objects.create(motsclef=request.POST[*'input_1'*])
polls = Polls.objects.create(motsclef=request.POST[*'input_2'*])
polls = Polls.objects.create(motsclef=request.POST[*'input_3'*])
)
--
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+***@googlegroups.com.
To post to this group, send email to django-***@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/e799579b-5132-45d4-a7d5-783fac61a54c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Continue reading on narkive:
Loading...