我有如下文件的國家的名單,顯示,從2維元組下拉列表
COUNTRIES = (
('AF', 'Afghanistan'),
('AX', '\xc5land Islands'),
('AL', 'Albania'),...
我想在我的下拉列表中只顯示各國的全名及保存只有模型中的全名。
現在我的models.py是
class UserProfiles(models.Model):
location = models.CharField(max_length=60, blank=True, null=True)
和forms.py是
class UserProfileForm(ModelForm):
location = forms.ChoiceField(choices=COUNTRIES)
如果我正確地得到您的問題,這不工作? COUNTRIES =( ( '阿富汗', '阿富汗'), ( '\ xc5land列島','\ xc5land羣島), ( '阿爾巴尼亞', '阿爾巴尼亞'),... – zubinmehta
這不是解決方案,但UserProfileForm是沒有必要的。你可以有這樣的事情:class UserProfiles(models.Model): location = models.CharField(max_length = 60,choices = COUNTRIES,blank = True,null = True) – Goin