Ticket #8040: 8040.patch
File 8040.patch, 2.3 KB (added by , 16 years ago) |
---|
-
django/db/models/fields/__init__.py
890 890 def get_internal_type(self): 891 891 return "SlugField" 892 892 893 def formfield(self, **kwargs): 894 defaults = {'form_class': forms.RegexField, 'regex': r'^[a-zA-Z0-9_-]+$', 895 'error_messages': {'invalid': _(u"Enter a valid 'slug' consisting of letters, numbers, underscores or hyphens.")}, 896 } 897 defaults.update(kwargs) 898 return super(SlugField, self).formfield(**defaults) 899 893 900 class SmallIntegerField(IntegerField): 894 901 def get_manipulator_field_objs(self): 895 902 return [oldforms.SmallIntegerField] -
tests/modeltests/model_forms/models.py
295 295 [<Category: Entertainment>, <Category: It's a test>, <Category: Third test>] 296 296 297 297 If you call save() with invalid data, you'll get a ValueError. 298 >>> f = CategoryForm({'name': '', 'slug': ' ', 'url': 'foo'})298 >>> f = CategoryForm({'name': '', 'slug': 'not a slug!', 'url': 'foo'}) 299 299 >>> f.errors['name'] 300 300 [u'This field is required.'] 301 301 >>> f.errors['slug'] 302 [u 'This field is required.']302 [u"Enter a valid 'slug' consisting of letters, numbers, underscores or hyphens."] 303 303 >>> f.cleaned_data 304 304 Traceback (most recent call last): 305 305 ... -
docs/modelforms.txt
65 65 (from ``django.contrib.localflavor.us``) 66 66 ``PositiveIntegerField`` ``IntegerField`` 67 67 ``PositiveSmallIntegerField`` ``IntegerField`` 68 ``SlugField`` ``CharField`` 68 ``SlugField`` ``RegexField`` accepting only letters, 69 numbers, underscores and hyphens 69 70 ``SmallIntegerField`` ``IntegerField`` 70 71 ``TextField`` ``CharField`` with ``widget=Textarea`` 71 72 ``TimeField`` ``TimeField``