Ticket #1296: slugfield.patch

File slugfield.patch, 4.4 KB (added by matt, 19 years ago)

Patch to allow SlugFields with maxlength greater than 50

  • django/contrib/admin/views/doc.py

     
    260260    'PhoneNumberField'          : _('Phone number'),
    261261    'PositiveIntegerField'      : _('Integer'),
    262262    'PositiveSmallIntegerField' : _('Integer'),
    263     'SlugField'                 : _('String (up to 50)'),
     263    'SlugField'                 : _('String (up to %(maxlength)s)'),
    264264    'SmallIntegerField'         : _('Integer'),
    265265    'TextField'                 : _('Text'),
    266266    'TimeField'                 : _('Time'),
  • django/core/db/backends/ado_mssql.py

     
    153153    'PhoneNumberField':  'varchar(20)',
    154154    'PositiveIntegerField': 'int CONSTRAINT [CK_int_pos_%(column)s] CHECK ([%(column)s] > 0)',
    155155    'PositiveSmallIntegerField': 'smallint CONSTRAINT [CK_smallint_pos_%(column)s] CHECK ([%(column)s] > 0)',
    156     'SlugField':         'varchar(50)',
     156    'SlugField':         'varchar(%(maxlength)s)',
    157157    'SmallIntegerField': 'smallint',
    158158    'TextField':         'text',
    159159    'TimeField':         'time',
  • django/core/db/backends/postgresql.py

     
    176176    'PhoneNumberField':  'varchar(20)',
    177177    'PositiveIntegerField': 'integer CHECK ("%(column)s" >= 0)',
    178178    'PositiveSmallIntegerField': 'smallint CHECK ("%(column)s" >= 0)',
    179     'SlugField':         'varchar(50)',
     179    'SlugField':         'varchar(%(maxlength)s)',
    180180    'SmallIntegerField': 'smallint',
    181181    'TextField':         'text',
    182182    'TimeField':         'time',
  • django/core/db/backends/sqlite3.py

     
    177177    'PhoneNumberField':             'varchar(20)',
    178178    'PositiveIntegerField':         'integer unsigned',
    179179    'PositiveSmallIntegerField':    'smallint unsigned',
    180     'SlugField':                    'varchar(50)',
     180    'SlugField':                    'varchar(%(maxlength)s)',
    181181    'SmallIntegerField':            'smallint',
    182182    'TextField':                    'text',
    183183    'TimeField':                    'time',
  • django/core/db/backends/mysql.py

     
    174174    'PhoneNumberField':  'varchar(20)',
    175175    'PositiveIntegerField': 'integer UNSIGNED',
    176176    'PositiveSmallIntegerField': 'smallint UNSIGNED',
    177     'SlugField':         'varchar(50)',
     177    'SlugField':         'varchar(%(maxlength)s)',
    178178    'SmallIntegerField': 'smallint',
    179179    'TextField':         'longtext',
    180180    'TimeField':         'time',
  • django/core/meta/fields.py

     
    604604
    605605class SlugField(Field):
    606606    def __init__(self, *args, **kwargs):
    607         kwargs['maxlength'] = 50
     607        # Default to a maxlength of 50 but allow overrides
     608        if not kwargs.has_key('maxlength'):
     609            kwargs['maxlength'] = 50
    608610        kwargs.setdefault('validator_list', []).append(validators.isSlug)
    609611        # Set db_index=True unless it's been set manually.
    610612        if not kwargs.has_key('db_index'):
  • docs/model-api.txt

     
    409409    "Slug" is a newspaper term. A slug is a short label for something,
    410410    containing only letters, numbers, underscores or hyphens. They're generally
    411411    used in URLs.
     412   
     413    If ``maxlength`` is specified, it will override the default length of 50.
    412414
    413     Implies ``maxlength=50`` and ``db_index=True``.
     415    Implies ``db_index=True``.
    414416
    415417    Accepts an extra option, ``prepopulate_from``, which is a list of fields
    416418    from which to auto-populate the slug, via JavaScript, in the object's admin
Back to Top