本文整理汇总了Python中django.forms.ModelForm.__new__方法的典型用法代码示例。如果您正苦于以下问题:Python ModelForm.__new__方法的具体用法?Python ModelForm.__new__怎么用?Python ModelForm.__new__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.forms.ModelForm
的用法示例。
在下文中一共展示了ModelForm.__new__方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __new__
# 需要导入模块: from django.forms import ModelForm [as 别名]
# 或者: from django.forms.ModelForm import __new__ [as 别名]
def __new__(cls, *args, **kwargs):
for field_name in cls.base_fields:
print(field_name)
field = cls.base_fields[field_name]
attr_dic = {'class':'form-control',
'placeholder':field.help_text,
}
field.widget.attrs.update(attr_dic)
return ModelForm.__new__(cls)
示例2: __new__
# 需要导入模块: from django.forms import ModelForm [as 别名]
# 或者: from django.forms.ModelForm import __new__ [as 别名]
def __new__(cls, *args, **kwargs):
#cls.base_fields是一个元祖,里面是 所有的 【(字段名,字段的对象),(),()】
for field_name in cls.base_fields:
field_obj = cls.base_fields[field_name]
#添加属性
field_obj.widget.attrs.update({'class':'form-control'})
if field_name in cls.Meta.readonly_fields:
field_obj.widget.attrs.update({'disabled':'true'})
return ModelForm.__new__(cls)
示例3: __new__
# 需要导入模块: from django.forms import ModelForm [as 别名]
# 或者: from django.forms.ModelForm import __new__ [as 别名]
def __new__(cls, *args, **kwargs):
# super(CustomerForm, self).__new__(*args, **kwargs)
# self.fields['customer_note'].widget.attrs['class'] = 'form-control'
#disabled_fields = ['qq', 'consultant']
for field_name in cls.base_fields:
field = cls.base_fields[field_name]
#print("field repr",field_name,field.__repr__())
attr_dic = {'placeholder': field.help_text}
if 'BooleanField' not in field.__repr__():
attr_dic.update({'class': 'form-control'})
#print("-->field",field)
if 'ModelChoiceField' in field.__repr__(): #fk field
attr_dic.update({'data-tag':field_name})
# if 'DateTimeField' in field.__repr__():
# attr_dic.update({'placeholder': field_name})
if cls.Meta.form_create is False:
if field_name in cls.Meta.admin.readonly_fields:
attr_dic['disabled'] = True
#print('----read only:',field_name)
field.widget.attrs.update(attr_dic)
print("modelf form admin class:",dir(cls.Meta))
return ModelForm.__new__(cls)