Ticket #8040: 8040.patch

File 8040.patch, 2.3 KB (added by Collin Grady, 16 years ago)

updated patch (minor position change in fields/init.py)

  • django/db/models/fields/__init__.py

     
    890890    def get_internal_type(self):
    891891        return "SlugField"
    892892
     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
    893900class SmallIntegerField(IntegerField):
    894901    def get_manipulator_field_objs(self):
    895902        return [oldforms.SmallIntegerField]
  • tests/modeltests/model_forms/models.py

     
    295295[<Category: Entertainment>, <Category: It's a test>, <Category: Third test>]
    296296
    297297If 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'})
    299299>>> f.errors['name']
    300300[u'This field is required.']
    301301>>> f.errors['slug']
    302 [u'This field is required.']
     302[u"Enter a valid 'slug' consisting of letters, numbers, underscores or hyphens."]
    303303>>> f.cleaned_data
    304304Traceback (most recent call last):
    305305...
  • docs/modelforms.txt

     
    6565                                     (from ``django.contrib.localflavor.us``)
    6666    ``PositiveIntegerField``         ``IntegerField``
    6767    ``PositiveSmallIntegerField``    ``IntegerField``
    68     ``SlugField``                    ``CharField``
     68    ``SlugField``                    ``RegexField`` accepting only letters,
     69                                     numbers, underscores and hyphens
    6970    ``SmallIntegerField``            ``IntegerField``
    7071    ``TextField``                    ``CharField`` with ``widget=Textarea``
    7172    ``TimeField``                    ``TimeField``
Back to Top