Django - USStateField vs USZipCodeField
Why is one of these a model and the other is a form? For example, in order to get it to behave correctly this is my model:
class UserProfile(models.Model):
state = USStateField()
zip = models.CharField(max_length=30)
and this is my form:
开发者_开发技巧class UserProfileForm(forms.ModelForm):
zip = USZipCodeField()
I would think that it would make sense for their to be a USZipCodeField model so that the code is symmetric
I think you probably just want to use USStateField
directly:
from django.contrib.localflavor.us.forms import USStateField
class UserProfileForm(forms.ModelForm):
state = USStateField()
zip = USZipCodeField()
class Meta:
model = UserProfile
Is there a reason you were using USZipCodeField
for your zip
field, but forms.ChoiceField
for your state?
精彩评论