如何从某种类型的特定模型中获取所有字段?
例如,我想从我的模型中获取所有为 PositiveIntegerField 的字段。
怎么做?
我问这个的原因是因为我有以下代码:
from django import forms
from hzmo_web.apps.hzmo.models import Report
class ReportForm(forms.ModelForm):
class Meta:
model = Report
def __init__(self, *args, **kw):
super(ReportForm, self).__init__(*args, **kw)
self.fields['osiguranika'].widget.attrs['class'] = 'biggerWidth'
self.fields['korisnika'].widget.attrs['class'] = 'biggerWidth'
self.fields['sredstva'].widget.attrs['class'] = 'biggerWidth'
self.fields['dzd_korisnika'].widget.attrs['class'] = 'biggerWidth'
self.fields['dzd_djece'].widget.attrs['class'] = 'biggerWidth'
self.fields['dzd_isplata'].widget.attrs['class'] = 'biggerWidth'
所有这些字段都是 PositiveIntegerField 类型,所以我想编写一些循环来缩短代码。