From 97eb38b21dfa2750f50b3a933adaf19661345dab Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Fri, 17 Feb 2006 18:15:07 +0000 Subject: [PATCH] Fixed #1296 -- Made SlugField maxlength configurable. Thanks, Matt git-svn-id: http://code.djangoproject.com/svn/django/trunk@2325 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/contrib/admin/views/doc.py | 2 +- django/core/db/backends/ado_mssql.py | 2 +- django/core/db/backends/mysql.py | 2 +- django/core/db/backends/postgresql.py | 2 +- django/core/db/backends/sqlite3.py | 2 +- django/core/meta/fields.py | 3 ++- docs/model-api.txt | 6 +++++- 7 files changed, 12 insertions(+), 7 deletions(-) diff --git a/django/contrib/admin/views/doc.py b/django/contrib/admin/views/doc.py index 5d73933139..0545d49367 100644 --- a/django/contrib/admin/views/doc.py +++ b/django/contrib/admin/views/doc.py @@ -260,7 +260,7 @@ DATA_TYPE_MAPPING = { 'PhoneNumberField' : _('Phone number'), 'PositiveIntegerField' : _('Integer'), 'PositiveSmallIntegerField' : _('Integer'), - 'SlugField' : _('String (up to 50)'), + 'SlugField' : _('String (up to %(maxlength)s)'), 'SmallIntegerField' : _('Integer'), 'TextField' : _('Text'), 'TimeField' : _('Time'), diff --git a/django/core/db/backends/ado_mssql.py b/django/core/db/backends/ado_mssql.py index bb5b628aca..80f174a7b2 100644 --- a/django/core/db/backends/ado_mssql.py +++ b/django/core/db/backends/ado_mssql.py @@ -153,7 +153,7 @@ DATA_TYPES = { 'PhoneNumberField': 'varchar(20)', 'PositiveIntegerField': 'int CONSTRAINT [CK_int_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', 'TextField': 'text', 'TimeField': 'time', diff --git a/django/core/db/backends/mysql.py b/django/core/db/backends/mysql.py index 84fe416f64..66376cdd1e 100644 --- a/django/core/db/backends/mysql.py +++ b/django/core/db/backends/mysql.py @@ -174,7 +174,7 @@ DATA_TYPES = { 'PhoneNumberField': 'varchar(20)', 'PositiveIntegerField': 'integer UNSIGNED', 'PositiveSmallIntegerField': 'smallint UNSIGNED', - 'SlugField': 'varchar(50)', + 'SlugField': 'varchar(%(maxlength)s)', 'SmallIntegerField': 'smallint', 'TextField': 'longtext', 'TimeField': 'time', diff --git a/django/core/db/backends/postgresql.py b/django/core/db/backends/postgresql.py index f70e8366f1..dcbd719bdc 100644 --- a/django/core/db/backends/postgresql.py +++ b/django/core/db/backends/postgresql.py @@ -176,7 +176,7 @@ DATA_TYPES = { 'PhoneNumberField': 'varchar(20)', 'PositiveIntegerField': 'integer CHECK ("%(column)s" >= 0)', 'PositiveSmallIntegerField': 'smallint CHECK ("%(column)s" >= 0)', - 'SlugField': 'varchar(50)', + 'SlugField': 'varchar(%(maxlength)s)', 'SmallIntegerField': 'smallint', 'TextField': 'text', 'TimeField': 'time', diff --git a/django/core/db/backends/sqlite3.py b/django/core/db/backends/sqlite3.py index 55e7d2af30..b8a661cf2b 100644 --- a/django/core/db/backends/sqlite3.py +++ b/django/core/db/backends/sqlite3.py @@ -177,7 +177,7 @@ DATA_TYPES = { 'PhoneNumberField': 'varchar(20)', 'PositiveIntegerField': 'integer unsigned', 'PositiveSmallIntegerField': 'smallint unsigned', - 'SlugField': 'varchar(50)', + 'SlugField': 'varchar(%(maxlength)s)', 'SmallIntegerField': 'smallint', 'TextField': 'text', 'TimeField': 'time', diff --git a/django/core/meta/fields.py b/django/core/meta/fields.py index e8ae73a84d..ea9f5d4bcc 100644 --- a/django/core/meta/fields.py +++ b/django/core/meta/fields.py @@ -604,7 +604,8 @@ class PositiveSmallIntegerField(IntegerField): class SlugField(Field): 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) # Set db_index=True unless it's been set manually. if not kwargs.has_key('db_index'): diff --git a/docs/model-api.txt b/docs/model-api.txt index d7ac7d6fe5..e84de76db7 100644 --- a/docs/model-api.txt +++ b/docs/model-api.txt @@ -410,7 +410,11 @@ Here are all available field types: containing only letters, numbers, underscores or hyphens. They're generally 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 from which to auto-populate the slug, via JavaScript, in the object's admin