1, students submit application data page as follows:
The page form some of the data is taken directly from the database, and do nothing to change
Create Customer form a 1,2, readonly_fields variable is stored in read-only properties field, exclude variables django form attribute has a non-display at a front end
#crm/forms.py
class CustomerForm(ModelForm):
"""客户表单"""
def __new__(cls,*args,**kwargs):
#super(CustomerForm,self).__new__(*args,**kwargs)
# print("request.POST:",request.POST)
#表名,表对象值
for field_name,field_obj in cls.base_fields.items():
#print(field_name,dir(field_obj))
#给表输入框添加class
field_obj.widget.attrs['class'] = 'form-control'
#在类Meta的readonly_fields中的字段增加disabled属性
if field_name in cls.Meta.readonly_fields:
#添加disabled属性
field_obj.widget.attrs['disabled'] = 'disabled'
return ModelForm.__new__(cls)
class Meta:
model =models.Customer
fields ='__all__'
#不在前端显示
exclude =["tags","content","memo","status","referral_from","consult_course"]
#只读属性
readonly_fields =["qq","consultant","source"]