問題:模板中創建form表單中的下拉列表, 前台打開頁面顯示object,而不是值,如圖:
嘗試了多種辦法無果,最后解決了,處理辦法是修改models.py,原來的model:
- class TechnicistLocation(models.Model): # 技術人員位置
- LocationName = models.CharField('位置名稱', max_length=20)
- class Meta:
- verbose_name_plural = '技術人員位置'
- app_label ="schedule"
- def __unicode__(self):
- return self.LocationName
修改后的model:
- class TechnicistLocation(models.Model): # 技術人員位置
- LocationName = models.CharField('位置名稱', max_length=20)
- class Meta:
- verbose_name_plural = '技術人員位置'
- app_label ="schedule"
- def __str__(self):
- return self.LocationName
區別就在倒數第二行,python3直接使用__str__(self)就可以了,如果是python2,則要用__unicode__(self)