开发者

Django - USStateField vs USZipCodeField

开发者 https://www.devze.com 2023-02-04 22:49 出处:网络
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:

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?

0

精彩评论

暂无评论...
验证码 换一张
取 消