iterate a save in a form view based on a field value

20 views
Skip to first unread message

MikeKJ

unread,
Jan 6, 2017, 10:21:18 AM1/6/17
to Django users
So I have a form of post values and one of the values is the number of resources to be used,  what I want to do is save multiple instances of the form data based on the resource quantity to be used.

ResourceObject is the model name

views.py snippet
[code]
            rqb = int(resource_quantity_used)
               for i in rqb:
                   i = ResourceObject()
                   i.resource = resource
                   i.resource_quantity_used = resource_quantity_used
                   i.date = date  //date of usage
                   i.start = start  //start time of usage
                   i.hours = hours  //number of hours to be used for
                   i.save()
[/code]
this currently throws  'int' object is not iterable  at 'for i in rqb' if I use for i in resource_quantity_used it doesnt iterate on the value of resource_quantity_used.

Many thanks

roboslone

unread,
Jan 6, 2017, 10:29:26 AM1/6/17
to django...@googlegroups.com
Hi! You probably want to use range() function for that.

--
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/47c6cd40-5d7f-4d10-8d3b-8f9e580485c8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages