I’m a django newbie.
I have this model:
class Item(models.Model):
name = models.CharField(max_length=255)
quantity = models.IntegerField()
How to create view to update quantity of my all Item?
views:
def item_list(request):
item = Product.objects.all()[:6]
return render_to_response('item.html',{'item':item},context_instance=RequestContext(request))
form:
from django import forms
class QuantityForm(forms.Form):
quan = forms.IntegerField()
template:
{% for i in item %}
{{ i.name }}
{{ i.quantity }}
{% endfor %}
I’m trying to do something like this(after clicking “update” value quantity in my model should be actualize):

Please any help. Thanks
First you need a view, which retrieves item id and quantity value, updates relative
Iteminstance and redirects you back to the page. Here is an example:Also you need to create urlpattern for the view in your
urls.py. For example:Then you can make a forms for each item on a template:
I’m trying to offer a solution as simple as possible. You should know that django provides a lot of cool stuff, that can help your to solve your problem much efficiently, such as forms, modelforms, formsets…