Django - LocalFlavor field for a model

1k Views Asked by At

I am trying to show a localflavor field for a telephone number.

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

1

There are 1 best solutions below

4
On BEST ANSWER

localflavors provide form fields, not widgets. You have to use it like this:

class AssociationForm(ModelForm):
    telephone = CAPhoneNumberField()

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