mirror of https://github.com/django/django.git
Changed database PhoneNumberField to use USPhoneNumberField as its newforms form field (instead of IntegerField)
git-svn-id: http://code.djangoproject.com/svn/django/trunk@4556 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
ec2eb4d18f
commit
abc949f584
|
@ -748,6 +748,12 @@ class PhoneNumberField(IntegerField):
|
||||||
def validate(self, field_data, all_data):
|
def validate(self, field_data, all_data):
|
||||||
validators.isValidPhone(field_data, all_data)
|
validators.isValidPhone(field_data, all_data)
|
||||||
|
|
||||||
|
def formfield(self, **kwargs):
|
||||||
|
from django.contrib.localflavor.usa.forms import USPhoneNumberField
|
||||||
|
defaults = {'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text}
|
||||||
|
defaults.update(kwargs)
|
||||||
|
return USPhoneNumberField(**defaults)
|
||||||
|
|
||||||
class PositiveIntegerField(IntegerField):
|
class PositiveIntegerField(IntegerField):
|
||||||
def get_manipulator_field_objs(self):
|
def get_manipulator_field_objs(self):
|
||||||
return [oldforms.PositiveIntegerField]
|
return [oldforms.PositiveIntegerField]
|
||||||
|
|
|
@ -54,6 +54,13 @@ class Article(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.headline
|
return self.headline
|
||||||
|
|
||||||
|
class PhoneNumber(models.Model):
|
||||||
|
phone = models.PhoneNumberField()
|
||||||
|
description = models.CharField(maxlength=20)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.phone
|
||||||
|
|
||||||
__test__ = {'API_TESTS': """
|
__test__ = {'API_TESTS': """
|
||||||
>>> from django.newforms import form_for_model, form_for_instance, save_instance, BaseForm, Form, CharField
|
>>> from django.newforms import form_for_model, form_for_instance, save_instance, BaseForm, Form, CharField
|
||||||
>>> import datetime
|
>>> import datetime
|
||||||
|
@ -445,4 +452,13 @@ ValidationError: [u'Select a valid choice. 10 is not one of the available choice
|
||||||
Traceback (most recent call last):
|
Traceback (most recent call last):
|
||||||
...
|
...
|
||||||
ValidationError: [u'Select a valid choice. 10 is not one of the available choices.']
|
ValidationError: [u'Select a valid choice. 10 is not one of the available choices.']
|
||||||
|
|
||||||
|
# PhoneNumberField ############################################################
|
||||||
|
|
||||||
|
>>> PhoneNumberForm = form_for_model(PhoneNumber)
|
||||||
|
>>> f = PhoneNumberForm({'phone': '(312) 555-1212', 'description': 'Assistance'})
|
||||||
|
>>> f.is_valid()
|
||||||
|
True
|
||||||
|
>>> f.clean_data
|
||||||
|
{'phone': u'312-555-1212', 'description': u'Assistance'}
|
||||||
"""}
|
"""}
|
||||||
|
|
Loading…
Reference in New Issue