class CustomBoundField(BoundField):
def label_tag(self, contents=None, attrs=None):
if self.field.required:
attrs = {'class': 'required'}
return super(CustomBoundField, self).label_tag(contents, attrs)
class ImportViewerForm(forms.Form):
url = fields.URLField(widget=forms.TextInput(attrs={'class': 'vTextField'}))
type = fields.ChoiceField(choices=[('o', 'Organisation'), ('p', 'Program')], widget=forms.RadioSelect,
help_text='Url contain infornation about this type')
source = fields.ChoiceField(choices=[('h', 'hodex'), ('s', 'studyfinder')], initial='h', widget=forms.RadioSelect)
def __getitem__(self, name):
"Returns a BoundField with the given name."
try:
field = self.fields[name]
except KeyError:
raise KeyError('Key %r not found in Form' % name)
return CustomBoundField(self, field, name)
class Media:
css = {'all': [settings.STATIC_URL + 'admin/css/forms.css']}
您需要的BoundField類改變方法label_tag,並用它在形式上
`你真的需要標籤標籤上的類?`,是的,如果你使用像引導程序或基礎的框架。 – vikki 2013-11-04 15:21:51