Django - 模型的LocalFlavor字段

时间:2014-01-04 22:05:55

标签: python django field django-localflavor

我正在尝试为电话号码显示localflavor字段。

以下是我的尝试:

 # 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,
    }

但它没有显示任何差异......它仍然是一个正常的输入字段......

谢谢, ARA

1 个答案:

答案 0 :(得分:0)

localflavors提供表单字段,而不是widgets。你必须像这样使用它:

class AssociationForm(ModelForm):
    telephone = CAPhoneNumberField()

    class Meta:
        model = Association
        fields = ('telephone','fax')