Fixed #1296 -- Made SlugField maxlength configurable. Thanks, Matt

git-svn-id: http://code.djangoproject.com/svn/django/trunk@2325 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2006-02-17 18:15:07 +00:00
parent 6b694097dc
commit 97eb38b21d
7 changed files with 12 additions and 7 deletions

View File

@ -260,7 +260,7 @@ DATA_TYPE_MAPPING = {
'PhoneNumberField' : _('Phone number'), 'PhoneNumberField' : _('Phone number'),
'PositiveIntegerField' : _('Integer'), 'PositiveIntegerField' : _('Integer'),
'PositiveSmallIntegerField' : _('Integer'), 'PositiveSmallIntegerField' : _('Integer'),
'SlugField' : _('String (up to 50)'), 'SlugField' : _('String (up to %(maxlength)s)'),
'SmallIntegerField' : _('Integer'), 'SmallIntegerField' : _('Integer'),
'TextField' : _('Text'), 'TextField' : _('Text'),
'TimeField' : _('Time'), 'TimeField' : _('Time'),

View File

@ -153,7 +153,7 @@ DATA_TYPES = {
'PhoneNumberField': 'varchar(20)', 'PhoneNumberField': 'varchar(20)',
'PositiveIntegerField': 'int CONSTRAINT [CK_int_pos_%(column)s] CHECK ([%(column)s] > 0)', 'PositiveIntegerField': 'int CONSTRAINT [CK_int_pos_%(column)s] CHECK ([%(column)s] > 0)',
'PositiveSmallIntegerField': 'smallint CONSTRAINT [CK_smallint_pos_%(column)s] CHECK ([%(column)s] > 0)', 'PositiveSmallIntegerField': 'smallint CONSTRAINT [CK_smallint_pos_%(column)s] CHECK ([%(column)s] > 0)',
'SlugField': 'varchar(50)', 'SlugField': 'varchar(%(maxlength)s)',
'SmallIntegerField': 'smallint', 'SmallIntegerField': 'smallint',
'TextField': 'text', 'TextField': 'text',
'TimeField': 'time', 'TimeField': 'time',

View File

@ -174,7 +174,7 @@ DATA_TYPES = {
'PhoneNumberField': 'varchar(20)', 'PhoneNumberField': 'varchar(20)',
'PositiveIntegerField': 'integer UNSIGNED', 'PositiveIntegerField': 'integer UNSIGNED',
'PositiveSmallIntegerField': 'smallint UNSIGNED', 'PositiveSmallIntegerField': 'smallint UNSIGNED',
'SlugField': 'varchar(50)', 'SlugField': 'varchar(%(maxlength)s)',
'SmallIntegerField': 'smallint', 'SmallIntegerField': 'smallint',
'TextField': 'longtext', 'TextField': 'longtext',
'TimeField': 'time', 'TimeField': 'time',

View File

@ -176,7 +176,7 @@ DATA_TYPES = {
'PhoneNumberField': 'varchar(20)', 'PhoneNumberField': 'varchar(20)',
'PositiveIntegerField': 'integer CHECK ("%(column)s" >= 0)', 'PositiveIntegerField': 'integer CHECK ("%(column)s" >= 0)',
'PositiveSmallIntegerField': 'smallint CHECK ("%(column)s" >= 0)', 'PositiveSmallIntegerField': 'smallint CHECK ("%(column)s" >= 0)',
'SlugField': 'varchar(50)', 'SlugField': 'varchar(%(maxlength)s)',
'SmallIntegerField': 'smallint', 'SmallIntegerField': 'smallint',
'TextField': 'text', 'TextField': 'text',
'TimeField': 'time', 'TimeField': 'time',

View File

@ -177,7 +177,7 @@ DATA_TYPES = {
'PhoneNumberField': 'varchar(20)', 'PhoneNumberField': 'varchar(20)',
'PositiveIntegerField': 'integer unsigned', 'PositiveIntegerField': 'integer unsigned',
'PositiveSmallIntegerField': 'smallint unsigned', 'PositiveSmallIntegerField': 'smallint unsigned',
'SlugField': 'varchar(50)', 'SlugField': 'varchar(%(maxlength)s)',
'SmallIntegerField': 'smallint', 'SmallIntegerField': 'smallint',
'TextField': 'text', 'TextField': 'text',
'TimeField': 'time', 'TimeField': 'time',

View File

@ -604,7 +604,8 @@ class PositiveSmallIntegerField(IntegerField):
class SlugField(Field): class SlugField(Field):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
kwargs['maxlength'] = 50 # Default to a maxlength of 50 but allow overrides.
kwargs['maxlength'] = kwargs.get('maxlength', 50)
kwargs.setdefault('validator_list', []).append(validators.isSlug) kwargs.setdefault('validator_list', []).append(validators.isSlug)
# Set db_index=True unless it's been set manually. # Set db_index=True unless it's been set manually.
if not kwargs.has_key('db_index'): if not kwargs.has_key('db_index'):

View File

@ -410,7 +410,11 @@ Here are all available field types:
containing only letters, numbers, underscores or hyphens. They're generally containing only letters, numbers, underscores or hyphens. They're generally
used in URLs. used in URLs.
Implies ``maxlength=50`` and ``db_index=True``. In the Django development version, you can specify ``maxlength``. If
``maxlength`` is not specified, Django will use a default length of 50. In
previous Django versions, there's no way to override the length of 50.
Implies ``db_index=True``.
Accepts an extra option, ``prepopulate_from``, which is a list of fields Accepts an extra option, ``prepopulate_from``, which is a list of fields
from which to auto-populate the slug, via JavaScript, in the object's admin from which to auto-populate the slug, via JavaScript, in the object's admin