开发者

set every single form readonly without using widgets in the model

I am trying to build a template with some forms. I have a model with about 400 attributes for one entity. Now i want to make two different templates. In one Template the attributes should be listed like django form do. In the other开发者_JAVA技巧 template the attributes should be set readonly.

I don't want to create two diffent Forms for every attribute by using widgets.

cust_form = GeneralDataForm(instance=_customer, auto_id=False, label_suffix='')

I tried inserting the widget here but it doesn't work.


using this code you can make any form readonly. are you looking for something like this?

cust_form_read_only = make_form_readonly(cust_form)

def make_form_readonly(form):
        for name, field in form.fields.items():
        field.widget.attrs['readonly'] = True
        field.widget.attrs['disabled'] = True
    return form
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜