表格.py
class PhoneForm(forms.ModelForm):
number1 = forms.IntegerField(required=False,error_messages={'invalid':'Enter a valid phone number'})
number2 = forms.IntegerField(required=False,error_messages={'invalid':'Enter a valid phone number'})
number3 = forms.IntegerField(required=False,error_messages={'invalid':'Enter a valid phone number'})
class Meta:
model = PhoneInfo
fields = ['name1','number1','name2','number2','name3','number3','emergency','emergency_number']
模型.py
class PhoneInfo(models.Model):
user = models.ForeignKey(User, null=True)
name1 = models.CharField('Name', max_length=100, null=True, blank=True)
number1 = models.CharField('Number',max_length=20, null=True, blank=True)
name2 = models.CharField('Name', max_length=100, null=True, blank=True)
number2 = models.CharField('Number', max_length=20, null=True, blank=True)
name3 = models.CharField('Name', max_length=100, null=True, blank=True)
number3 = models.CharField('Number',max_length=20, null=True, blank=True)
emergency = models.CharField('Emergency', max_length=100, null=True, blank=True)
emergency_number = models.CharField('Emergency Number',max_length=20, null=True, blank=True)
nmber1、number2 和 number3 用于保存 11 位电话号码。我的问题是,如果我在保存“0”后将第 1 位添加为“0”从表单字段中消失。我在第 1 位后添加“0”正在保存和显示。问题在于:08854215452 第一个零在保存后消失。我想在保存带有 STD 代码的电话号码时也显示这一点。
Traceback:
File "/usr/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
101. request.path_info)
File "/usr/lib/python2.7/site-packages/django/core/urlresolvers.py" in resolve
252. sub_match = pattern.resolve(new_path)
File "/usr/lib/python2.7/site-packages/django/core/urlresolvers.py" in resolve
252. sub_match = pattern.resolve(new_path)
File "/usr/lib/python2.7/site-packages/django/core/urlresolvers.py" in resolve
158. return ResolverMatch(self.callback, args, kwargs, self.name)
File "/usr/lib/python2.7/site-packages/django/core/urlresolvers.py" in _get_callback
164. self._callback = get_callable(self._callback_str)
File "/usr/lib/python2.7/site-packages/django/utils/functional.py" in wrapper
124. result = func(*args)
File "/usr/lib/python2.7/site-packages/django/core/urlresolvers.py" in get_callable
91. lookup_view = getattr(import_module(mod_name), func_name)
File "/usr/lib/python2.7/site-packages/django/utils/importlib.py" in import_module
35. __import__(name)
File "/root/Projects/ir_uploaded_copy/ir/setting/views.py" in <module>
22. from setting.forms import *
File "/root/Projects/ir_uploaded_copy/ir/setting/forms.py" in <module>
151. class PhoneForm(forms.ModelForm):
File "/root/Projects/ir_uploaded_copy/ir/setting/forms.py" in PhoneForm
162. emergency_number = forms.RegexField(regex=r'^\+?(\d{3}-?\d+{7})$', error_messages = {'invalid':'Enter a valid phone number'})
File "/usr/lib/python2.7/site-packages/django/forms/fields.py" in __init__
437. regex = re.compile(regex)
File "/usr/lib/python2.7/re.py" in compile
190. return _compile(pattern, flags)
File "/usr/lib/python2.7/re.py" in _compile
245. raise error, v # invalid expression
Exception Type: error at /setting/call/
Exception Value: multiple repeat
谢谢