2012-08-31 14 views
1

我基於模型,在那裏我有一個布爾字段,因爲這創建一個表單:Django的布爾現場返回「---------」爲價值

project_type = models.CharField(max_length=50, choices=JOB_TYPES) 

的選擇是:

JOB_TYPES = (
    ('fulltime', _('Fulltid')), 
    ('project', _('Prosjektbasert')), 
) 

要顯示輸入類型爲單選按鈕,而不是,我這樣做:

class AddJob(ModelForm): 
     class Meta: 
      model = Jobs 
    widgets = { 
     'project_type': RadioSelect(), 
    } 

在HTML,形式輸出看起來像這樣:

<label for="id_for_project_type_0">Project type</label> 
<ul> 
<li><label for="id_for_project_type_0"><input checked="checked" type="radio"  id="id_for_project_type_0" value="" name="project_type" /> ---------</label></li> 
<li><label for="id_for_project_type_1"><input type="radio" id="id_for_project_type_1" value="fulltime" name="project_type" /> Fulltid</label></li> 
<li><label for="id_for_project_type_2"><input type="radio" id="id_for_project_type_2" value="project" name="project_type" /> Prosjektbasert</label></li> 
</ul> 

爲什麼我的值爲0?我只在模型中指定了兩個值。我該如何擺脫它?

感謝提前:)

回答

0

你需要指定一個default valueproject_type

project_type = models.CharField(max_length=50, choices=JOB_TYPES, 
           default=JOB_TYPES[0][0])