【发布时间】:2013-09-13 06:27:20
【问题描述】:
我正在使用自定义 Modelchoicefield 类来获取部分用户组的全名,而不是他们的用户名:
class UserModelChoiceField(forms.ModelChoiceField):
def label_from_instance(self, obj):
return "%s" % (obj.get_full_name())
在表单中,我在为“class Meta”中的其他字段定义小部件之前调用这个类:
tutor = UserModelChoiceField(User.objects.filter(groups__name='teachers'))
有没有办法将小部件添加到“导师”字段?我想在 HTML 输出中添加“class='form-control'”。
谢谢, 托比
【问题讨论】:
标签: django django-forms django-templates