Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

git-svn-id: http://code.djangoproject.com/svn/django/trunk@2325 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 97eb38b21dfa2750f50b3a933adaf19661345dab 1 parent 6b69409
Adrian Holovaty authored February 17, 2006
2  django/contrib/admin/views/doc.py
@@ -260,7 +260,7 @@ def get_return_data_type(func_name):
260 260
     'PhoneNumberField'          : _('Phone number'),
261 261
     'PositiveIntegerField'      : _('Integer'),
262 262
     'PositiveSmallIntegerField' : _('Integer'),
263  
-    'SlugField'                 : _('String (up to 50)'),
  263
+    'SlugField'                 : _('String (up to %(maxlength)s)'),
264 264
     'SmallIntegerField'         : _('Integer'),
265 265
     'TextField'                 : _('Text'),
266 266
     'TimeField'                 : _('Time'),
2  django/core/db/backends/ado_mssql.py
@@ -153,7 +153,7 @@ def get_relations(cursor, table_name):
153 153
     'PhoneNumberField':  'varchar(20)',
154 154
     'PositiveIntegerField': 'int CONSTRAINT [CK_int_pos_%(column)s] CHECK ([%(column)s] > 0)',
155 155
     'PositiveSmallIntegerField': 'smallint CONSTRAINT [CK_smallint_pos_%(column)s] CHECK ([%(column)s] > 0)',
156  
-    'SlugField':         'varchar(50)',
  156
+    'SlugField':         'varchar(%(maxlength)s)',
157 157
     'SmallIntegerField': 'smallint',
158 158
     'TextField':         'text',
159 159
     'TimeField':         'time',
2  django/core/db/backends/mysql.py
@@ -174,7 +174,7 @@ def get_relations(cursor, table_name):
174 174
     'PhoneNumberField':  'varchar(20)',
175 175
     'PositiveIntegerField': 'integer UNSIGNED',
176 176
     'PositiveSmallIntegerField': 'smallint UNSIGNED',
177  
-    'SlugField':         'varchar(50)',
  177
+    'SlugField':         'varchar(%(maxlength)s)',
178 178
     'SmallIntegerField': 'smallint',
179 179
     'TextField':         'longtext',
180 180
     'TimeField':         'time',
2  django/core/db/backends/postgresql.py
@@ -176,7 +176,7 @@ def get_relations(cursor, table_name):
176 176
     'PhoneNumberField':  'varchar(20)',
177 177
     'PositiveIntegerField': 'integer CHECK ("%(column)s" >= 0)',
178 178
     'PositiveSmallIntegerField': 'smallint CHECK ("%(column)s" >= 0)',
179  
-    'SlugField':         'varchar(50)',
  179
+    'SlugField':         'varchar(%(maxlength)s)',
180 180
     'SmallIntegerField': 'smallint',
181 181
     'TextField':         'text',
182 182
     'TimeField':         'time',
2  django/core/db/backends/sqlite3.py
@@ -177,7 +177,7 @@ def get_relations(cursor, table_name):
177 177
     'PhoneNumberField':             'varchar(20)',
178 178
     'PositiveIntegerField':         'integer unsigned',
179 179
     'PositiveSmallIntegerField':    'smallint unsigned',
180  
-    'SlugField':                    'varchar(50)',
  180
+    'SlugField':                    'varchar(%(maxlength)s)',
181 181
     'SmallIntegerField':            'smallint',
182 182
     'TextField':                    'text',
183 183
     'TimeField':                    'time',
3  django/core/meta/fields.py
@@ -604,7 +604,8 @@ def get_manipulator_field_objs(self):
604 604
 
605 605
 class SlugField(Field):
606 606
     def __init__(self, *args, **kwargs):
607  
-        kwargs['maxlength'] = 50
  607
+        # Default to a maxlength of 50 but allow overrides.
  608
+        kwargs['maxlength'] = kwargs.get('maxlength', 50)
608 609
         kwargs.setdefault('validator_list', []).append(validators.isSlug)
609 610
         # Set db_index=True unless it's been set manually.
610 611
         if not kwargs.has_key('db_index'):
6  docs/model-api.txt
@@ -410,7 +410,11 @@ Here are all available field types:
410 410
     containing only letters, numbers, underscores or hyphens. They're generally
411 411
     used in URLs.
412 412
 
413  
-    Implies ``maxlength=50`` and ``db_index=True``.
  413
+    In the Django development version, you can specify ``maxlength``. If
  414
+    ``maxlength`` is not specified, Django will use a default length of 50. In
  415
+    previous Django versions, there's no way to override the length of 50.
  416
+
  417
+    Implies ``db_index=True``.
414 418
 
415 419
     Accepts an extra option, ``prepopulate_from``, which is a list of fields
416 420
     from which to auto-populate the slug, via JavaScript, in the object's admin

0 notes on commit 97eb38b

Please sign in to comment.
Something went wrong with that request. Please try again.