[英]Django - LocalFlavor field for a model
I am trying to show a localflavor field for a telephone number. 我正在尝试显示电话号码的localflavor字段。
Here is what I tried: 这是我尝试过的:
# Create your models here.
class Association(models.Model):
formfield_overrides = {
models: {'widget': CAPhoneNumberField},
}
city = models.CharField(max_length=25,unique=True)
slug = AutoSlugField(unique=True,populate_from='city')
general_manager = models.CharField(max_length=75)
address = models.TextField()
email = models.EmailField()
telephone = models.CharField(max_length=15)
telephone_extension = models.CharField(max_length=5)
fax = models.CharField(max_length=10)
link = models.URLField()
logo = models.ImageField(upload_to='uploads/img/associations')
def __str__(self): # Python 3: def __str__(self):
return self.city
# Create forms
class AssociationForm(ModelForm):
class Meta:
model = Association
fields = ('telephone','fax')
widgets = {
'name': CAPhoneNumberField,
}
But it's not showing any differences...it's still a normal input field.... 但这并没有显示任何差异...它仍然是正常的输入字段...
Thanks, Ara 谢谢,阿拉
localflavors
provide form fields, not widgets
. localflavors
提供表单字段,而不是widgets
。 You have to use it like this: 您必须像这样使用它:
class AssociationForm(ModelForm):
telephone = CAPhoneNumberField()
class Meta:
model = Association
fields = ('telephone','fax')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.