ModelForm으로 만든 양식에 "phone"필드가 있습니다. 이 필드의 유효성을 검사하고 싶습니다. 여기 models.py의 코드는 다음과 같습니다ModelForm 유효성을 검사하는 가장 좋은 방법
class UserProfile(models.Model):
user = models.ForeignKey(User, unique=True)
phone = models.CharField(max_length=20, validators=[validate_phone])
forms.py :
내가 알아 낸 것 어떻게 지금까지 THER이 장고 ModelForm에서 만든 양식을 검증 할 수있는 몇 가지 방법이 있습니다에서class UserProfileResetForm(ModelForm):
class Meta:
model = UserProfile
exclude = ('user')
. 나는 그들의 적어도 3 : (지금처럼) RegexField 2 등 UserProfileResetForm에서 1. 재정의 전화가 그래서 조금 혼란 스러워요 3.
UserProfileResetForm
에 clean_phone 방법을 만들 검사기를 사용하여 ... 이 일을하는 가장 좋은 방법은 무엇입니까?
개인적으로 장황한 사람이 필드의 유효성을 검사하기 때문에 유효성 검사기 방법을 사용하는 것이 좋습니다. 특정 국가 만 지원할 경우 https://docs.djangoproject.com/en/1.3/ref/contrib/localflavor/ - localflavor 등을 사용할 수 있습니다. – karthikr