Monday, October 1, 2012

Re: How to implement a form to update the quantity?

Hi!

You can use something like:

{% for item in garage.garagecar_set.all %}
  Car: {{item.car.name}} Price: {{item.car.price}} Quantity: {{item.quantity}} ID: {{item.car.id}}
<form action="../update_q/{{item.pk}}/" method="post"/>
{{form.q}}
<input type="submit" value="update"/>
</form>
 {% endfor %}

and view like

def update_q(request, garagecar_id):
# get garagecar by id here, create form from request, set new value, save()


it to submit forms with ajax, to not reload entire page every time.


P.S.

it looks you are implementing Many-to-Many-Through relation. Django has support for it out of the box
https://docs.djangoproject.com/en/dev/topics/db/models/#extra-fields-on-many-to-many-relationships



--
Regards,
Anton Baklanov

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment