python - Django form/formset for a tabular list of forms -


a picture worth thousand words. here i'm trying accomplish:

tabular_formset

this simple enough manually creating table within template so:

<form>   <table class="table">     <thead><tr><th>{% trans 'name' %}</th><th>{% trans 'available quantity' %}</th></tr></thead>     <tbody>       {% p in products %}       <tr><td>{{p.name}}</td><td>{{p.available}}</td><td><input name="{{p.id}}" type="number" /></td></tr>       {% endfor %}     </tbody>   </table> <form> 

however, doing way makes hassle deal submitted form data error validation.

i'd prefer in django form (formset seems more suitable). i've tried this approach doesn't make want easier accomplish.

here's minified version of (relevant) models:

class product(models.model):     name = models.charfield("name", max_length=50) class orderitem(models.model):     product = models.foreignkey('product', verbose_name=_("product"))     quantity = models.floatfield("quantity") 

is there elegant way in django i'm not considering?


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -