开发者

django formset and and initial data

I have a simple model and a simple form. The form looks like this:

class AddForm(forms.Form):
    quantity = forms.IntegerField(label='', widget=forms.TextInput(attrs={'size':'2'}))
    product_id = forms.IntegerField(widget=forms.HiddenInput)

In my template there's a object_list containing all the model-objects. What I want is: next to each model-object a开发者_运维知识库 form to enter the "quantity". The "product_id"-field has to have the id of each model as initial data. I guess I have to use Formsets for this, but I don't understand how to set the initial data from database-data and how to make Formsets display a form for each model-object.

Thanks in advance Jacques


As the form you want to add is so simple, it's easier just to add the product id in the template with something like

<input type="hidden" name="product_id" value="{{ object.id }}" />

rather than adding complicated formsets.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜