[英]Why can't I set my Django Model's USPhoneNumberField to null=True, blank=True?
My Django Model: 我的Django模型:
from localflavor.us.forms import USPhoneNumberField
class Profile(models.Model):
cellPhone = USPhoneNumberField(null=True, blank=True,)
This gives me the following error when I do a manage.py syncdb: 当我执行manage.py syncdb时,这给我以下错误:
cellPhone = USPhoneNumberField(null=True, blank=True,)
TypeError: __init__() got an unexpected keyword argument 'null'
How can I make this field optional if it won't let me declare it as null=True like I do for so many other fields? 如果不允许我像其他许多字段一样将其声明为null = True,如何使该字段为可选?
USPhoneNumberField
is a form
type, not a model type USPhoneNumberField
是form
类型,而不是模型类型
The usage (typically) is: 用法(通常)是:
class Profile(models.Model):
cellPhone = models.CharField(max_length=20, null=True, blank=True,)
and forms.py 和forms.py
class ProfileForm(forms.Form): #or forms.ModelForm
cellPhone = forms.USPhoneNumberField(...)
Here is the documentation 这是文档
class localflavor.us.models.PhoneNumberField(*args, **kwargs) A CharField that checks that the value is a valid USA-style phone number (in the format XXX-XXX-XXXX).
class localflavor.us.models.PhoneNumberField(* args,** kwargs)一个CharField,它检查该值是否为有效的美国式电话号码(格式为XXX-XXX-XXXX)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.