0

我正在尝试显示电话号码的本地风味字段。

这是我尝试过的:

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

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

谢谢,阿拉

4

1 回答 1

0

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

class AssociationForm(ModelForm):
    telephone = CAPhoneNumberField()

    class Meta:
        model = Association
        fields = ('telephone','fax')
于 2014-01-04T22:12:35.613 回答