Django 1.7, localflavor 1.1 USStateSelect()

208 Views Asked by At

I am using Django 1.7 and just installed localflavor 1.1. Now, while creating a default user, I want to use the USStateSelect() field. While creating a Nurse, which extends default user, I am getting all kinds of errors. Here is my current code:

models.py:

from localflavor.us.forms import USStateSelect

class MyUser(AbstractBaseUser):
    #Address
    house_number = models.IntegerField(default = 0)
    street = models.CharField(max_length = 30, default = "")
    city = models.CharField(max_length = 20, default = "")
    state = USStateSelect()
    zip_Code = models.IntegerField(default = 0)

class Nurse(MyUser):
    #Other fields

forms.py:

class NurseCreationForm(ModelForm):
password1 = forms.CharField(label='Password', widget=forms.PasswordInput)
password2 = forms.CharField(label='Password confirmation', widget=forms.PasswordInput)

class Meta:
    model = Nurse
    fields = ('email', 'first_name', 'last_name', 'department','state',)

error:

File "C:\Python34\lib\site-packages\django\forms\models.py", line 294, in
__new__raise FieldError(message)
django.core.exceptions.FieldError: Unknown field(s) (state) specified for  
Nurse

I haven't been able to find a valid solution for Django 1.7 anywhere online. Thanks in advance for the help!

1

There are 1 best solutions below

0
On BEST ANSWER

Your problem is that you are trying to use the form field USStateSelect in your models. You should use the model field USStateField instead. Try the following:

from localflavor.us.models import USStateField

class MyUser(AbstractBaseUser):
    #Address
    house_number = models.IntegerField(default = 0)
    street = models.CharField(max_length = 30, default = "")
    city = models.CharField(max_length = 20, default = "")
    state = USStateField()
    zip_Code = models.IntegerField(default = 0)

You will have to create a migration and run it after updating your models.