Django - USStateField与USZipCodeField的区别
为什么其中一个是模型,另一个是表单呢?比如,为了让它正常工作,这是我的模型:
class UserProfile(models.Model):
state = USStateField()
zip = models.CharField(max_length=30)
而这是我的表单:
class UserProfileForm(forms.ModelForm):
zip = USZipCodeField()
我觉得应该有一个USZipCodeField模型,这样代码看起来会更对称一些。
1 个回答
2
我觉得你可能只想直接使用 USStateField
这个东西:
from django.contrib.localflavor.us.forms import USStateField
class UserProfileForm(forms.ModelForm):
state = USStateField()
zip = USZipCodeField()
class Meta:
model = UserProfile
你为什么要在 zip
字段用 USZipCodeField
,而在州的字段用 forms.ChoiceField
呢?