Django在表单上添加空字段

时间:2010-11-08 09:23:37

标签: django django-forms

我使用self.fields来获取所有用户的全名而不仅仅是用户名,现在我想添加一个空字段作为第一选择......

目前

def __init__(self, user, *args, **kwargs):
    super(TrophiesForm, self).__init__(*args, **kwargs)
    self.fields['outfitter'].choices = [(user.pk, user.get_full_name()) for user in users]

1 个答案:

答案 0 :(得分:2)

self.fields['outfitter'].choices = [('', '')] + [(user.pk, user.get_full_name()) for user in users]