Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #2101 -- Renamed `maxlength` argument to `max_length` for oldfo…

…rms `FormField`s and db model `Field`s. This is fully backwards compatible at the moment since the legacy `maxlength` argument is still supported. Using `maxlength` will, however, issue a `PendingDeprecationWarning` when used.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@5803 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 212ee65be782240554749f25bbd3772240d56fff 1 parent 973f44a
Gary Wilson Jr. authored August 05, 2007

Showing 88 changed files with 647 additions and 407 deletions. Show diff stats Hide diff stats

  1. 2  django/contrib/admin/models.py
  2. 2  django/contrib/admin/templatetags/admin_modify.py
  3. 4  django/contrib/admin/views/doc.py
  4. 20  django/contrib/auth/forms.py
  5. 14  django/contrib/auth/models.py
  6. 8  django/contrib/comments/models.py
  7. 6  django/contrib/comments/views/comments.py
  8. 6  django/contrib/contenttypes/models.py
  9. 6  django/contrib/flatpages/models.py
  10. 4  django/contrib/redirects/models.py
  11. 2  django/contrib/sessions/models.py
  12. 4  django/contrib/sites/models.py
  13. 16  django/core/management.py
  14. 6  django/db/backends/ado_mssql/creation.py
  15. 6  django/db/backends/mysql/creation.py
  16. 6  django/db/backends/mysql_old/creation.py
  17. 4  django/db/backends/oracle/creation.py
  18. 6  django/db/backends/postgresql/creation.py
  19. 6  django/db/backends/sqlite3/creation.py
  20. 2  django/db/backends/sqlite3/introspection.py
  21. 22  django/db/models/fields/__init__.py
  22. 1  django/newforms/fields.py
  23. 116  django/oldforms/__init__.py
  24. 67  django/utils/maxlength.py
  25. 20  docs/contributing.txt
  26. 10  docs/db-api.txt
  27. 10  docs/forms.txt
  28. 110  docs/model-api.txt
  29. 8  docs/newforms.txt
  30. 6  docs/overview.txt
  31. 8  docs/sites.txt
  32. 4  docs/testing.txt
  33. 6  docs/tutorial01.txt
  34. 2  docs/tutorial02.txt
  35. 2  tests/modeltests/basic/models.py
  36. 4  tests/modeltests/choices/models.py
  37. 6  tests/modeltests/custom_columns/models.py
  38. 10  tests/modeltests/custom_managers/models.py
  39. 2  tests/modeltests/custom_methods/models.py
  40. 8  tests/modeltests/custom_pk/models.py
  41. 2  tests/modeltests/field_defaults/models.py
  42. 2  tests/modeltests/fixtures/models.py
  43. 8  tests/modeltests/generic_relations/models.py
  44. 4  tests/modeltests/get_latest/models.py
  45. 4  tests/modeltests/get_object_or_404/models.py
  46. 4  tests/modeltests/get_or_create/models.py
  47. 44  tests/modeltests/invalid_models/models.py
  48. 2  tests/modeltests/lookup/models.py
  49. 2  tests/modeltests/m2m_and_m2o/models.py
  50. 8  tests/modeltests/m2m_intermediary/models.py
  51. 4  tests/modeltests/m2m_multiple/models.py
  52. 2  tests/modeltests/m2m_recursive/models.py
  53. 2  tests/modeltests/m2o_recursive/models.py
  54. 2  tests/modeltests/m2o_recursive2/models.py
  55. 6  tests/modeltests/manipulators/models.py
  56. 4  tests/modeltests/many_to_many/models.py
  57. 6  tests/modeltests/many_to_one/models.py
  58. 4  tests/modeltests/many_to_one_null/models.py
  59. 10  tests/modeltests/model_forms/models.py
  60. 4  tests/modeltests/model_inheritance/models.py
  61. 4  tests/modeltests/mutually_referential/models.py
  62. 12  tests/modeltests/one_to_one/models.py
  63. 2  tests/modeltests/or_lookups/models.py
  64. 2  tests/modeltests/ordering/models.py
  65. 2  tests/modeltests/pagination/models.py
  66. 4  tests/modeltests/properties/models.py
  67. 16  tests/modeltests/reserved_names/models.py
  68. 6  tests/modeltests/reverse_lookup/models.py
  69. 4  tests/modeltests/save_delete_hooks/models.py
  70. 16  tests/modeltests/select_related/models.py
  71. 6  tests/modeltests/serializers/models.py
  72. 4  tests/modeltests/str/models.py
  73. 4  tests/modeltests/transactions/models.py
  74. 2  tests/modeltests/validation/models.py
  75. 2  tests/regressiontests/bug639/models.py
  76. 2  tests/regressiontests/datatypes/models.py
  77. 8  tests/regressiontests/fixtures_regress/models.py
  78. 2  tests/regressiontests/initial_sql_regress/models.py
  79. 74  tests/regressiontests/invalid_admin_options/models.py
  80. 6  tests/regressiontests/many_to_one_regress/models.py
  81. 0  tests/regressiontests/maxlength/__init__.py
  82. 0  tests/regressiontests/maxlength/models.py
  83. 160  tests/regressiontests/maxlength/tests.py
  84. 2  tests/regressiontests/model_regress/models.py
  85. 4  tests/regressiontests/null_queries/models.py
  86. 6  tests/regressiontests/one_to_one_regress/models.py
  87. 16  tests/regressiontests/serializers_regress/models.py
  88. 12  tests/regressiontests/string_lookup/models.py
2  django/contrib/admin/models.py
@@ -18,7 +18,7 @@ class LogEntry(models.Model):
18 18
     user = models.ForeignKey(User)
19 19
     content_type = models.ForeignKey(ContentType, blank=True, null=True)
20 20
     object_id = models.TextField(_('object id'), blank=True, null=True)
21  
-    object_repr = models.CharField(_('object repr'), maxlength=200)
  21
+    object_repr = models.CharField(_('object repr'), max_length=200)
22 22
     action_flag = models.PositiveSmallIntegerField(_('action flag'))
23 23
     change_message = models.TextField(_('change message'), blank=True)
24 24
     objects = LogEntryManager()
2  django/contrib/admin/templatetags/admin_modify.py
@@ -192,7 +192,7 @@ def auto_populated_field_script(auto_pop_fields, change = False):
192 192
             t.append(u'document.getElementById("id_%s").onkeyup = function() {' \
193 193
                      ' var e = document.getElementById("id_%s");' \
194 194
                      ' if(!e._changed) { e.value = URLify(%s, %s);} }; ' % (
195  
-                     f, field.name, add_values, field.maxlength))
  195
+                     f, field.name, add_values, field.max_length))
196 196
     return u''.join(t)
197 197
 auto_populated_field_script = register.simple_tag(auto_populated_field_script)
198 198
 
4  django/contrib/admin/views/doc.py
@@ -291,7 +291,7 @@ def get_return_data_type(func_name):
291 291
 DATA_TYPE_MAPPING = {
292 292
     'AutoField'                 : _('Integer'),
293 293
     'BooleanField'              : _('Boolean (Either True or False)'),
294  
-    'CharField'                 : _('String (up to %(maxlength)s)'),
  294
+    'CharField'                 : _('String (up to %(max_length)s)'),
295 295
     'CommaSeparatedIntegerField': _('Comma-separated integers'),
296 296
     'DateField'                 : _('Date (without time)'),
297 297
     'DateTimeField'             : _('Date (with time)'),
@@ -310,7 +310,7 @@ def get_return_data_type(func_name):
310 310
     'PhoneNumberField'          : _('Phone number'),
311 311
     'PositiveIntegerField'      : _('Integer'),
312 312
     'PositiveSmallIntegerField' : _('Integer'),
313  
-    'SlugField'                 : _('String (up to %(maxlength)s)'),
  313
+    'SlugField'                 : _('String (up to %(max_length)s)'),
314 314
     'SmallIntegerField'         : _('Integer'),
315 315
     'TextField'                 : _('Text'),
316 316
     'TimeField'                 : _('Time'),
20  django/contrib/auth/forms.py
@@ -10,10 +10,10 @@ class UserCreationForm(oldforms.Manipulator):
10 10
     "A form that creates a user, with no privileges, from the given username and password."
11 11
     def __init__(self):
12 12
         self.fields = (
13  
-            oldforms.TextField(field_name='username', length=30, maxlength=30, is_required=True,
  13
+            oldforms.TextField(field_name='username', length=30, max_length=30, is_required=True,
14 14
                 validator_list=[validators.isAlphaNumeric, self.isValidUsername]),
15  
-            oldforms.PasswordField(field_name='password1', length=30, maxlength=60, is_required=True),
16  
-            oldforms.PasswordField(field_name='password2', length=30, maxlength=60, is_required=True,
  15
+            oldforms.PasswordField(field_name='password1', length=30, max_length=60, is_required=True),
  16
+            oldforms.PasswordField(field_name='password2', length=30, max_length=60, is_required=True,
17 17
                 validator_list=[validators.AlwaysMatchesOtherField('password1', _("The two password fields didn't match."))]),
18 18
         )
19 19
 
@@ -42,9 +42,9 @@ def __init__(self, request=None):
42 42
         """
43 43
         self.request = request
44 44
         self.fields = [
45  
-            oldforms.TextField(field_name="username", length=15, maxlength=30, is_required=True,
  45
+            oldforms.TextField(field_name="username", length=15, max_length=30, is_required=True,
46 46
                 validator_list=[self.isValidUser, self.hasCookiesEnabled]),
47  
-            oldforms.PasswordField(field_name="password", length=15, maxlength=30, is_required=True),
  47
+            oldforms.PasswordField(field_name="password", length=15, max_length=30, is_required=True),
48 48
         ]
49 49
         self.user_cache = None
50 50
 
@@ -111,11 +111,11 @@ class PasswordChangeForm(oldforms.Manipulator):
111 111
     def __init__(self, user):
112 112
         self.user = user
113 113
         self.fields = (
114  
-            oldforms.PasswordField(field_name="old_password", length=30, maxlength=30, is_required=True,
  114
+            oldforms.PasswordField(field_name="old_password", length=30, max_length=30, is_required=True,
115 115
                 validator_list=[self.isValidOldPassword]),
116  
-            oldforms.PasswordField(field_name="new_password1", length=30, maxlength=30, is_required=True,
  116
+            oldforms.PasswordField(field_name="new_password1", length=30, max_length=30, is_required=True,
117 117
                 validator_list=[validators.AlwaysMatchesOtherField('new_password2', _("The two 'new password' fields didn't match."))]),
118  
-            oldforms.PasswordField(field_name="new_password2", length=30, maxlength=30, is_required=True),
  118
+            oldforms.PasswordField(field_name="new_password2", length=30, max_length=30, is_required=True),
119 119
         )
120 120
 
121 121
     def isValidOldPassword(self, new_data, all_data):
@@ -133,8 +133,8 @@ class AdminPasswordChangeForm(oldforms.Manipulator):
133 133
     def __init__(self, user):
134 134
         self.user = user
135 135
         self.fields = (
136  
-            oldforms.PasswordField(field_name='password1', length=30, maxlength=60, is_required=True),
137  
-            oldforms.PasswordField(field_name='password2', length=30, maxlength=60, is_required=True,
  136
+            oldforms.PasswordField(field_name='password1', length=30, max_length=60, is_required=True),
  137
+            oldforms.PasswordField(field_name='password2', length=30, max_length=60, is_required=True,
138 138
                 validator_list=[validators.AlwaysMatchesOtherField('password1', _("The two password fields didn't match."))]),
139 139
         )
140 140
 
14  django/contrib/auth/models.py
@@ -50,9 +50,9 @@ class Permission(models.Model):
50 50
 
51 51
     Three basic permissions -- add, change and delete -- are automatically created for each Django model.
52 52
     """
53  
-    name = models.CharField(_('name'), maxlength=50)
  53
+    name = models.CharField(_('name'), max_length=50)
54 54
     content_type = models.ForeignKey(ContentType)
55  
-    codename = models.CharField(_('codename'), maxlength=100)
  55
+    codename = models.CharField(_('codename'), max_length=100)
56 56
 
57 57
     class Meta:
58 58
         verbose_name = _('permission')
@@ -70,7 +70,7 @@ class Group(models.Model):
70 70
 
71 71
     Beyond permissions, groups are a convenient way to categorize users to apply some label, or extended functionality, to them. For example, you could create a group 'Special users', and you could write code that would do special things to those users -- such as giving them access to a members-only portion of your site, or sending them members-only e-mail messages.
72 72
     """
73  
-    name = models.CharField(_('name'), maxlength=80, unique=True)
  73
+    name = models.CharField(_('name'), max_length=80, unique=True)
74 74
     permissions = models.ManyToManyField(Permission, verbose_name=_('permissions'), blank=True, filter_interface=models.HORIZONTAL)
75 75
 
76 76
     class Meta:
@@ -108,11 +108,11 @@ class User(models.Model):
108 108
 
109 109
     Username and password are required. Other fields are optional.
110 110
     """
111  
-    username = models.CharField(_('username'), maxlength=30, unique=True, validator_list=[validators.isAlphaNumeric], help_text=_("Required. 30 characters or fewer. Alphanumeric characters only (letters, digits and underscores)."))
112  
-    first_name = models.CharField(_('first name'), maxlength=30, blank=True)
113  
-    last_name = models.CharField(_('last name'), maxlength=30, blank=True)
  111
+    username = models.CharField(_('username'), max_length=30, unique=True, validator_list=[validators.isAlphaNumeric], help_text=_("Required. 30 characters or fewer. Alphanumeric characters only (letters, digits and underscores)."))
  112
+    first_name = models.CharField(_('first name'), max_length=30, blank=True)
  113
+    last_name = models.CharField(_('last name'), max_length=30, blank=True)
114 114
     email = models.EmailField(_('e-mail address'), blank=True)
115  
-    password = models.CharField(_('password'), maxlength=128, help_text=_("Use '[algo]$[salt]$[hexdigest]' or use the <a href=\"password/\">change password form</a>."))
  115
+    password = models.CharField(_('password'), max_length=128, help_text=_("Use '[algo]$[salt]$[hexdigest]' or use the <a href=\"password/\">change password form</a>."))
116 116
     is_staff = models.BooleanField(_('staff status'), default=False, help_text=_("Designates whether the user can log into this admin site."))
117 117
     is_active = models.BooleanField(_('active'), default=True, help_text=_("Designates whether this user can log into the Django admin. Unselect this instead of deleting accounts."))
118 118
     is_superuser = models.BooleanField(_('superuser status'), default=False, help_text=_("Designates that this user has all permissions without explicitly assigning them."))
8  django/contrib/comments/models.py
@@ -65,8 +65,8 @@ class Comment(models.Model):
65 65
     user = models.ForeignKey(User, raw_id_admin=True)
66 66
     content_type = models.ForeignKey(ContentType)
67 67
     object_id = models.IntegerField(_('object ID'))
68  
-    headline = models.CharField(_('headline'), maxlength=255, blank=True)
69  
-    comment = models.TextField(_('comment'), maxlength=3000)
  68
+    headline = models.CharField(_('headline'), max_length=255, blank=True)
  69
+    comment = models.TextField(_('comment'), max_length=3000)
70 70
     rating1 = models.PositiveSmallIntegerField(_('rating #1'), blank=True, null=True)
71 71
     rating2 = models.PositiveSmallIntegerField(_('rating #2'), blank=True, null=True)
72 72
     rating3 = models.PositiveSmallIntegerField(_('rating #3'), blank=True, null=True)
@@ -164,8 +164,8 @@ class FreeComment(models.Model):
164 164
     # A FreeComment is a comment by a non-registered user.
165 165
     content_type = models.ForeignKey(ContentType)
166 166
     object_id = models.IntegerField(_('object ID'))
167  
-    comment = models.TextField(_('comment'), maxlength=3000)
168  
-    person_name = models.CharField(_("person's name"), maxlength=50)
  167
+    comment = models.TextField(_('comment'), max_length=3000)
  168
+    person_name = models.CharField(_("person's name"), max_length=50)
169 169
     submit_date = models.DateTimeField(_('date/time submitted'), auto_now_add=True)
170 170
     is_public = models.BooleanField(_('is public'))
171 171
     ip_address = models.IPAddressField(_('ip address'))
6  django/contrib/comments/views/comments.py
@@ -29,7 +29,7 @@ def get_validator_list(rating_num):
29 29
             else:
30 30
                 return []
31 31
         self.fields.extend([
32  
-            oldforms.LargeTextField(field_name="comment", maxlength=3000, is_required=True,
  32
+            oldforms.LargeTextField(field_name="comment", max_length=3000, is_required=True,
33 33
                 validator_list=[self.hasNoProfanities]),
34 34
             oldforms.RadioSelectField(field_name="rating1", choices=choices,
35 35
                 is_required=ratings_required and num_rating_choices > 0,
@@ -122,9 +122,9 @@ class PublicFreeCommentManipulator(oldforms.Manipulator):
122 122
     "Manipulator that handles public free (unregistered) comments"
123 123
     def __init__(self):
124 124
         self.fields = (
125  
-            oldforms.TextField(field_name="person_name", maxlength=50, is_required=True,
  125
+            oldforms.TextField(field_name="person_name", max_length=50, is_required=True,
126 126
                 validator_list=[self.hasNoProfanities]),
127  
-            oldforms.LargeTextField(field_name="comment", maxlength=3000, is_required=True,
  127
+            oldforms.LargeTextField(field_name="comment", max_length=3000, is_required=True,
128 128
                 validator_list=[self.hasNoProfanities]),
129 129
         )
130 130
 
6  django/contrib/contenttypes/models.py
@@ -32,9 +32,9 @@ def clear_cache(self):
32 32
         CONTENT_TYPE_CACHE = {}
33 33
 
34 34
 class ContentType(models.Model):
35  
-    name = models.CharField(maxlength=100)
36  
-    app_label = models.CharField(maxlength=100)
37  
-    model = models.CharField(_('python model class name'), maxlength=100)
  35
+    name = models.CharField(max_length=100)
  36
+    app_label = models.CharField(max_length=100)
  37
+    model = models.CharField(_('python model class name'), max_length=100)
38 38
     objects = ContentTypeManager()
39 39
     class Meta:
40 40
         verbose_name = _('content type')
6  django/contrib/flatpages/models.py
@@ -4,12 +4,12 @@
4 4
 from django.utils.translation import ugettext_lazy as _
5 5
 
6 6
 class FlatPage(models.Model):
7  
-    url = models.CharField(_('URL'), maxlength=100, validator_list=[validators.isAlphaNumericURL], db_index=True,
  7
+    url = models.CharField(_('URL'), max_length=100, validator_list=[validators.isAlphaNumericURL], db_index=True,
8 8
         help_text=_("Example: '/about/contact/'. Make sure to have leading and trailing slashes."))
9  
-    title = models.CharField(_('title'), maxlength=200)
  9
+    title = models.CharField(_('title'), max_length=200)
10 10
     content = models.TextField(_('content'))
11 11
     enable_comments = models.BooleanField(_('enable comments'))
12  
-    template_name = models.CharField(_('template name'), maxlength=70, blank=True,
  12
+    template_name = models.CharField(_('template name'), max_length=70, blank=True,
13 13
         help_text=_("Example: 'flatpages/contact_page.html'. If this isn't provided, the system will use 'flatpages/default.html'."))
14 14
     registration_required = models.BooleanField(_('registration required'), help_text=_("If this is checked, only logged-in users will be able to view the page."))
15 15
     sites = models.ManyToManyField(Site)
4  django/contrib/redirects/models.py
@@ -4,9 +4,9 @@
4 4
 
5 5
 class Redirect(models.Model):
6 6
     site = models.ForeignKey(Site, radio_admin=models.VERTICAL)
7  
-    old_path = models.CharField(_('redirect from'), maxlength=200, db_index=True,
  7
+    old_path = models.CharField(_('redirect from'), max_length=200, db_index=True,
8 8
         help_text=_("This should be an absolute path, excluding the domain name. Example: '/events/search/'."))
9  
-    new_path = models.CharField(_('redirect to'), maxlength=200, blank=True,
  9
+    new_path = models.CharField(_('redirect to'), max_length=200, blank=True,
10 10
         help_text=_("This can be either an absolute path (as above) or a full URL starting with 'http://'."))
11 11
 
12 12
     class Meta:
2  django/contrib/sessions/models.py
@@ -65,7 +65,7 @@ class Session(models.Model):
65 65
     the sessions documentation that is shipped with Django (also available
66 66
     on the Django website).
67 67
     """
68  
-    session_key = models.CharField(_('session key'), maxlength=40, primary_key=True)
  68
+    session_key = models.CharField(_('session key'), max_length=40, primary_key=True)
69 69
     session_data = models.TextField(_('session data'))
70 70
     expire_date = models.DateTimeField(_('expire date'))
71 71
     objects = SessionManager()
4  django/contrib/sites/models.py
@@ -12,8 +12,8 @@ def get_current(self):
12 12
         return self.get(pk=sid)
13 13
 
14 14
 class Site(models.Model):
15  
-    domain = models.CharField(_('domain name'), maxlength=100)
16  
-    name = models.CharField(_('display name'), maxlength=50)
  15
+    domain = models.CharField(_('domain name'), max_length=100)
  16
+    name = models.CharField(_('display name'), max_length=50)
17 17
     objects = SiteManager()
18 18
     class Meta:
19 19
         db_table = 'django_site'
16  django/core/management.py
@@ -910,9 +910,9 @@ def inspectdb():
910 910
                     field_type, new_params = field_type
911 911
                     extra_params.update(new_params)
912 912
 
913  
-                # Add maxlength for all CharFields.
  913
+                # Add max_length for all CharFields.
914 914
                 if field_type == 'CharField' and row[3]:
915  
-                    extra_params['maxlength'] = row[3]
  915
+                    extra_params['max_length'] = row[3]
916 916
 
917 917
                 if field_type == 'DecimalField':
918 918
                     extra_params['max_digits'] = row[4]
@@ -987,8 +987,8 @@ def get_validation_errors(outfile, app=None):
987 987
         for f in opts.fields:
988 988
             if f.name == 'id' and not f.primary_key and opts.pk.name == 'id':
989 989
                 e.add(opts, '"%s": You can\'t use "id" as a field name, because each model automatically gets an "id" field if none of the fields have primary_key=True. You need to either remove/rename your "id" field or add primary_key=True to a field.' % f.name)
990  
-            if isinstance(f, models.CharField) and f.maxlength in (None, 0):
991  
-                e.add(opts, '"%s": CharFields require a "maxlength" attribute.' % f.name)
  990
+            if isinstance(f, models.CharField) and f.max_length in (None, 0):
  991
+                e.add(opts, '"%s": CharFields require a "max_length" attribute.' % f.name)
992 992
             if isinstance(f, models.DecimalField):
993 993
                 if f.decimal_places is None:
994 994
                     e.add(opts, '"%s": DecimalFields require a "decimal_places" attribute.' % f.name)
@@ -1013,11 +1013,11 @@ def get_validation_errors(outfile, app=None):
1013 1013
             if f.db_index not in (None, True, False):
1014 1014
                 e.add(opts, '"%s": "db_index" should be either None, True or False.' % f.name)
1015 1015
 
1016  
-            # Check that maxlength <= 255 if using older MySQL versions.
  1016
+            # Check that max_length <= 255 if using older MySQL versions.
1017 1017
             if settings.DATABASE_ENGINE == 'mysql':
1018 1018
                 db_version = connection.get_server_version()
1019  
-                if db_version < (5, 0, 3) and isinstance(f, (models.CharField, models.CommaSeparatedIntegerField, models.SlugField)) and f.maxlength > 255:
1020  
-                    e.add(opts, '"%s": %s cannot have a "maxlength" greater than 255 when you are using a version of MySQL prior to 5.0.3 (you are using %s).' % (f.name, f.__class__.__name__, '.'.join([str(n) for n in db_version[:3]])))
  1019
+                if db_version < (5, 0, 3) and isinstance(f, (models.CharField, models.CommaSeparatedIntegerField, models.SlugField)) and f.max_length > 255:
  1020
+                    e.add(opts, '"%s": %s cannot have a "max_length" greater than 255 when you are using a version of MySQL prior to 5.0.3 (you are using %s).' % (f.name, f.__class__.__name__, '.'.join([str(n) for n in db_version[:3]])))
1021 1021
 
1022 1022
             # Check to see if the related field will clash with any
1023 1023
             # existing fields, m2m fields, m2m related objects or related objects
@@ -1252,7 +1252,7 @@ def createcachetable(tablename):
1252 1252
     from django.db import backend, connection, transaction, models
1253 1253
     fields = (
1254 1254
         # "key" is a reserved word in MySQL, so use "cache_key" instead.
1255  
-        models.CharField(name='cache_key', maxlength=255, unique=True, primary_key=True),
  1255
+        models.CharField(name='cache_key', max_length=255, unique=True, primary_key=True),
1256 1256
         models.TextField(name='value'),
1257 1257
         models.DateTimeField(name='expires', db_index=True),
1258 1258
     )
6  django/db/backends/ado_mssql/creation.py
... ...
@@ -1,8 +1,8 @@
1 1
 DATA_TYPES = {
2 2
     'AutoField':         'int IDENTITY (1, 1)',
3 3
     'BooleanField':      'bit',
4  
-    'CharField':         'varchar(%(maxlength)s)',
5  
-    'CommaSeparatedIntegerField': 'varchar(%(maxlength)s)',
  4
+    'CharField':         'varchar(%(max_length)s)',
  5
+    'CommaSeparatedIntegerField': 'varchar(%(max_length)s)',
6 6
     'DateField':         'smalldatetime',
7 7
     'DateTimeField':     'smalldatetime',
8 8
     'DecimalField':      'numeric(%(max_digits)s, %(decimal_places)s)',
@@ -17,7 +17,7 @@
17 17
     'PhoneNumberField':  'varchar(20)',
18 18
     'PositiveIntegerField': 'int CONSTRAINT [CK_int_pos_%(column)s] CHECK ([%(column)s] > 0)',
19 19
     'PositiveSmallIntegerField': 'smallint CONSTRAINT [CK_smallint_pos_%(column)s] CHECK ([%(column)s] > 0)',
20  
-    'SlugField':         'varchar(%(maxlength)s)',
  20
+    'SlugField':         'varchar(%(max_length)s)',
21 21
     'SmallIntegerField': 'smallint',
22 22
     'TextField':         'text',
23 23
     'TimeField':         'time',
6  django/db/backends/mysql/creation.py
@@ -5,8 +5,8 @@
5 5
 DATA_TYPES = {
6 6
     'AutoField':         'integer AUTO_INCREMENT',
7 7
     'BooleanField':      'bool',
8  
-    'CharField':         'varchar(%(maxlength)s)',
9  
-    'CommaSeparatedIntegerField': 'varchar(%(maxlength)s)',
  8
+    'CharField':         'varchar(%(max_length)s)',
  9
+    'CommaSeparatedIntegerField': 'varchar(%(max_length)s)',
10 10
     'DateField':         'date',
11 11
     'DateTimeField':     'datetime',
12 12
     'DecimalField':      'numeric(%(max_digits)s, %(decimal_places)s)',
@@ -21,7 +21,7 @@
21 21
     'PhoneNumberField':  'varchar(20)',
22 22
     'PositiveIntegerField': 'integer UNSIGNED',
23 23
     'PositiveSmallIntegerField': 'smallint UNSIGNED',
24  
-    'SlugField':         'varchar(%(maxlength)s)',
  24
+    'SlugField':         'varchar(%(max_length)s)',
25 25
     'SmallIntegerField': 'smallint',
26 26
     'TextField':         'longtext',
27 27
     'TimeField':         'time',
6  django/db/backends/mysql_old/creation.py
@@ -5,8 +5,8 @@
5 5
 DATA_TYPES = {
6 6
     'AutoField':         'integer AUTO_INCREMENT',
7 7
     'BooleanField':      'bool',
8  
-    'CharField':         'varchar(%(maxlength)s)',
9  
-    'CommaSeparatedIntegerField': 'varchar(%(maxlength)s)',
  8
+    'CharField':         'varchar(%(max_length)s)',
  9
+    'CommaSeparatedIntegerField': 'varchar(%(max_length)s)',
10 10
     'DateField':         'date',
11 11
     'DateTimeField':     'datetime',
12 12
     'DecimalField':      'numeric(%(max_digits)s, %(decimal_places)s)',
@@ -21,7 +21,7 @@
21 21
     'PhoneNumberField':  'varchar(20)',
22 22
     'PositiveIntegerField': 'integer UNSIGNED',
23 23
     'PositiveSmallIntegerField': 'smallint UNSIGNED',
24  
-    'SlugField':         'varchar(%(maxlength)s)',
  24
+    'SlugField':         'varchar(%(max_length)s)',
25 25
     'SmallIntegerField': 'smallint',
26 26
     'TextField':         'longtext',
27 27
     'TimeField':         'time',
4  django/db/backends/oracle/creation.py
@@ -8,8 +8,8 @@
8 8
 DATA_TYPES = {
9 9
     'AutoField':                    'NUMBER(11)',
10 10
     'BooleanField':                 'NUMBER(1) CHECK (%(column)s IN (0,1))',
11  
-    'CharField':                    'NVARCHAR2(%(maxlength)s)',
12  
-    'CommaSeparatedIntegerField':   'VARCHAR2(%(maxlength)s)',
  11
+    'CharField':                    'NVARCHAR2(%(max_length)s)',
  12
+    'CommaSeparatedIntegerField':   'VARCHAR2(%(max_length)s)',
13 13
     'DateField':                    'DATE',
14 14
     'DateTimeField':                'TIMESTAMP',
15 15
     'DecimalField':                 'NUMBER(%(max_digits)s, %(decimal_places)s)',
6  django/db/backends/postgresql/creation.py
@@ -5,8 +5,8 @@
5 5
 DATA_TYPES = {
6 6
     'AutoField':         'serial',
7 7
     'BooleanField':      'boolean',
8  
-    'CharField':         'varchar(%(maxlength)s)',
9  
-    'CommaSeparatedIntegerField': 'varchar(%(maxlength)s)',
  8
+    'CharField':         'varchar(%(max_length)s)',
  9
+    'CommaSeparatedIntegerField': 'varchar(%(max_length)s)',
10 10
     'DateField':         'date',
11 11
     'DateTimeField':     'timestamp with time zone',
12 12
     'DecimalField':      'numeric(%(max_digits)s, %(decimal_places)s)',
@@ -21,7 +21,7 @@
21 21
     'PhoneNumberField':  'varchar(20)',
22 22
     'PositiveIntegerField': 'integer CHECK ("%(column)s" >= 0)',
23 23
     'PositiveSmallIntegerField': 'smallint CHECK ("%(column)s" >= 0)',
24  
-    'SlugField':         'varchar(%(maxlength)s)',
  24
+    'SlugField':         'varchar(%(max_length)s)',
25 25
     'SmallIntegerField': 'smallint',
26 26
     'TextField':         'text',
27 27
     'TimeField':         'time',
6  django/db/backends/sqlite3/creation.py
@@ -4,8 +4,8 @@
4 4
 DATA_TYPES = {
5 5
     'AutoField':                    'integer',
6 6
     'BooleanField':                 'bool',
7  
-    'CharField':                    'varchar(%(maxlength)s)',
8  
-    'CommaSeparatedIntegerField':   'varchar(%(maxlength)s)',
  7
+    'CharField':                    'varchar(%(max_length)s)',
  8
+    'CommaSeparatedIntegerField':   'varchar(%(max_length)s)',
9 9
     'DateField':                    'date',
10 10
     'DateTimeField':                'datetime',
11 11
     'DecimalField':                 'decimal',
@@ -20,7 +20,7 @@
20 20
     'PhoneNumberField':             'varchar(20)',
21 21
     'PositiveIntegerField':         'integer unsigned',
22 22
     'PositiveSmallIntegerField':    'smallint unsigned',
23  
-    'SlugField':                    'varchar(%(maxlength)s)',
  23
+    'SlugField':                    'varchar(%(max_length)s)',
24 24
     'SmallIntegerField':            'smallint',
25 25
     'TextField':                    'text',
26 26
     'TimeField':                    'time',
2  django/db/backends/sqlite3/introspection.py
@@ -81,7 +81,7 @@ def __getitem__(self, key):
81 81
             import re
82 82
             m = re.search(r'^\s*(?:var)?char\s*\(\s*(\d+)\s*\)\s*$', key)
83 83
             if m:
84  
-                return ('CharField', {'maxlength': int(m.group(1))})
  84
+                return ('CharField', {'max_length': int(m.group(1))})
85 85
             raise KeyError
86 86
 
87 87
 DATA_TYPES_REVERSE = FlexibleFieldLookupDict()
22  django/db/models/fields/__init__.py
@@ -11,6 +11,7 @@
11 11
 from django.utils.text import capfirst
12 12
 from django.utils.translation import ugettext_lazy, ugettext as _
13 13
 from django.utils.encoding import smart_unicode, force_unicode, smart_str
  14
+from django.utils.maxlength import LegacyMaxlength
14 15
 import datetime, os, time
15 16
 try:
16 17
     import decimal
@@ -63,6 +64,9 @@ def manipulator_validator_unique(f, opts, self, field_data, all_data):
63 64
 #     getattr(obj, opts.pk.attname)
64 65
 
65 66
 class Field(object):
  67
+    # Provide backwards compatibility for the maxlength attribute and
  68
+    # argument for this class and all subclasses.
  69
+    __metaclass__ = LegacyMaxlength
66 70
 
67 71
     # Designates whether empty strings fundamentally are allowed at the
68 72
     # database level.
@@ -72,7 +76,7 @@ class Field(object):
72 76
     creation_counter = 0
73 77
 
74 78
     def __init__(self, verbose_name=None, name=None, primary_key=False,
75  
-        maxlength=None, unique=False, blank=False, null=False, db_index=False,
  79
+        max_length=None, unique=False, blank=False, null=False, db_index=False,
76 80
         core=False, rel=None, default=NOT_PROVIDED, editable=True, serialize=True,
77 81
         prepopulate_from=None, unique_for_date=None, unique_for_month=None,
78 82
         unique_for_year=None, validator_list=None, choices=None, radio_admin=None,
@@ -80,7 +84,7 @@ def __init__(self, verbose_name=None, name=None, primary_key=False,
80 84
         self.name = name
81 85
         self.verbose_name = verbose_name
82 86
         self.primary_key = primary_key
83  
-        self.maxlength, self.unique = maxlength, unique
  87
+        self.max_length, self.unique = max_length, unique
84 88
         self.blank, self.null = blank, null
85 89
         # Oracle treats the empty string ('') as null, so coerce the null
86 90
         # option whenever '' is a possible value.
@@ -244,8 +248,8 @@ def get_manipulator_field_names(self, name_prefix):
244 248
 
245 249
     def prepare_field_objs_and_params(self, manipulator, name_prefix):
246 250
         params = {'validator_list': self.validator_list[:]}
247  
-        if self.maxlength and not self.choices: # Don't give SelectFields a maxlength parameter.
248  
-            params['maxlength'] = self.maxlength
  251
+        if self.max_length and not self.choices: # Don't give SelectFields a max_length parameter.
  252
+            params['max_length'] = self.max_length
249 253
 
250 254
         if self.choices:
251 255
             if self.radio_admin:
@@ -461,7 +465,7 @@ def to_python(self, value):
461 465
         return smart_unicode(value)
462 466
 
463 467
     def formfield(self, **kwargs):
464  
-        defaults = {'max_length': self.maxlength}
  468
+        defaults = {'max_length': self.max_length}
465 469
         defaults.update(kwargs)
466 470
         return super(CharField, self).formfield(**defaults)
467 471
 
@@ -670,7 +674,7 @@ def formfield(self, **kwargs):
670 674
 
671 675
 class EmailField(CharField):
672 676
     def __init__(self, *args, **kwargs):
673  
-        kwargs['maxlength'] = 75
  677
+        kwargs['max_length'] = 75
674 678
         CharField.__init__(self, *args, **kwargs)
675 679
 
676 680
     def get_internal_type(self):
@@ -829,7 +833,7 @@ def formfield(self, **kwargs):
829 833
 class IPAddressField(Field):
830 834
     empty_strings_allowed = False
831 835
     def __init__(self, *args, **kwargs):
832  
-        kwargs['maxlength'] = 15
  836
+        kwargs['max_length'] = 15
833 837
         Field.__init__(self, *args, **kwargs)
834 838
 
835 839
     def get_manipulator_field_objs(self):
@@ -877,7 +881,7 @@ def get_manipulator_field_objs(self):
877 881
 
878 882
 class SlugField(Field):
879 883
     def __init__(self, *args, **kwargs):
880  
-        kwargs['maxlength'] = kwargs.get('maxlength', 50)
  884
+        kwargs['max_length'] = kwargs.get('max_length', 50)
881 885
         kwargs.setdefault('validator_list', []).append(validators.isSlug)
882 886
         # Set db_index=True unless it's been set manually.
883 887
         if 'db_index' not in kwargs:
@@ -963,7 +967,7 @@ def formfield(self, **kwargs):
963 967
 
964 968
 class URLField(CharField):
965 969
     def __init__(self, verbose_name=None, name=None, verify_exists=True, **kwargs):
966  
-        kwargs['maxlength'] = kwargs.get('maxlength', 200)
  970
+        kwargs['max_length'] = kwargs.get('max_length', 200)
967 971
         if verify_exists:
968 972
             kwargs.setdefault('validator_list', []).append(validators.isExistingURL)
969 973
         self.verify_exists = verify_exists
1  django/newforms/fields.py
@@ -120,6 +120,7 @@ def clean(self, value):
120 120
 
121 121
     def widget_attrs(self, widget):
122 122
         if self.max_length is not None and isinstance(widget, (TextInput, PasswordInput)):
  123
+            # The HTML attribute is maxlength, not max_length.
123 124
             return {'maxlength': str(self.max_length)}
124 125
 
125 126
 class IntegerField(Field):
116  django/oldforms/__init__.py
@@ -4,6 +4,7 @@
4 4
 from django.conf import settings
5 5
 from django.utils.translation import ugettext, ungettext
6 6
 from django.utils.encoding import smart_unicode, force_unicode
  7
+from django.utils.maxlength import LegacyMaxlength
7 8
 
8 9
 FORM_FIELD_ID_PREFIX = 'id_'
9 10
 
@@ -302,6 +303,9 @@ class FormField(object):
302 303
     Subclasses should also implement a render(data) method, which is responsible
303 304
     for rending the form field in XHTML.
304 305
     """
  306
+    # Provide backwards compatibility for the maxlength attribute and
  307
+    # argument for this class and all subclasses.
  308
+    __metaclass__ = LegacyMaxlength
305 309
 
306 310
     def __str__(self):
307 311
         return unicode(self).encode('utf-8')
@@ -390,19 +394,19 @@ def get_id(self):
390 394
 
391 395
 class TextField(FormField):
392 396
     input_type = "text"
393  
-    def __init__(self, field_name, length=30, maxlength=None, is_required=False, validator_list=None, member_name=None):
  397
+    def __init__(self, field_name, length=30, max_length=None, is_required=False, validator_list=None, member_name=None):
394 398
         if validator_list is None: validator_list = []
395 399
         self.field_name = field_name
396  
-        self.length, self.maxlength = length, maxlength
  400
+        self.length, self.max_length = length, max_length
397 401
         self.is_required = is_required
398 402
         self.validator_list = [self.isValidLength, self.hasNoNewlines] + validator_list
399 403
         if member_name != None:
400 404
             self.member_name = member_name
401 405
 
402 406
     def isValidLength(self, data, form):
403  
-        if data and self.maxlength and len(smart_unicode(data)) > self.maxlength:
  407
+        if data and self.max_length and len(smart_unicode(data)) > self.max_length:
404 408
             raise validators.ValidationError, ungettext("Ensure your text is less than %s character.",
405  
-                "Ensure your text is less than %s characters.", self.maxlength) % self.maxlength
  409
+                "Ensure your text is less than %s characters.", self.max_length) % self.max_length
406 410
 
407 411
     def hasNoNewlines(self, data, form):
408 412
         if data and '\n' in data:
@@ -411,12 +415,12 @@ def hasNoNewlines(self, data, form):
411 415
     def render(self, data):
412 416
         if data is None:
413 417
             data = u''
414  
-        maxlength = u''
415  
-        if self.maxlength:
416  
-            maxlength = u'maxlength="%s" ' % self.maxlength
  418
+        max_length = u''
  419
+        if self.max_length:
  420
+            max_length = u'maxlength="%s" ' % self.max_length
417 421
         return u'<input type="%s" id="%s" class="v%s%s" name="%s" size="%s" value="%s" %s/>' % \
418 422
             (self.input_type, self.get_id(), self.__class__.__name__, self.is_required and u' required' or '',
419  
-            self.field_name, self.length, escape(data), maxlength)
  423
+            self.field_name, self.length, escape(data), max_length)
420 424
 
421 425
     def html2python(data):
422 426
         return data
@@ -426,14 +430,14 @@ class PasswordField(TextField):
426 430
     input_type = "password"
427 431
 
428 432
 class LargeTextField(TextField):
429  
-    def __init__(self, field_name, rows=10, cols=40, is_required=False, validator_list=None, maxlength=None):
  433
+    def __init__(self, field_name, rows=10, cols=40, is_required=False, validator_list=None, max_length=None):
430 434
         if validator_list is None: validator_list = []
431 435
         self.field_name = field_name
432 436
         self.rows, self.cols, self.is_required = rows, cols, is_required
433 437
         self.validator_list = validator_list[:]
434  
-        if maxlength:
  438
+        if max_length:
435 439
             self.validator_list.append(self.isValidLength)
436  
-            self.maxlength = maxlength
  440
+            self.max_length = max_length
437 441
 
438 442
     def render(self, data):
439 443
         if data is None:
@@ -710,12 +714,12 @@ def isValidImage(self, field_data, all_data):
710 714
 ####################
711 715
 
712 716
 class IntegerField(TextField):
713  
-    def __init__(self, field_name, length=10, maxlength=None, is_required=False, validator_list=None, member_name=None):
  717
+    def __init__(self, field_name, length=10, max_length=None, is_required=False, validator_list=None, member_name=None):
714 718
         if validator_list is None: validator_list = []
715 719
         validator_list = [self.isInteger] + validator_list
716 720
         if member_name is not None:
717 721
             self.member_name = member_name
718  
-        TextField.__init__(self, field_name, length, maxlength, is_required, validator_list)
  722
+        TextField.__init__(self, field_name, length, max_length, is_required, validator_list)
719 723
 
720 724
     def isInteger(self, field_data, all_data):
721 725
         try:
@@ -730,57 +734,57 @@ def html2python(data):
730 734
     html2python = staticmethod(html2python)
731 735
 
732 736
 class SmallIntegerField(IntegerField):
733  
-    def __init__(self, field_name, length=5, maxlength=5, is_required=False, validator_list=None):
  737
+    def __init__(self, field_name, length=5, max_length=5, is_required=False, validator_list=None):
734 738
         if validator_list is None: validator_list = []
735 739
         validator_list = [self.isSmallInteger] + validator_list
736  
-        IntegerField.__init__(self, field_name, length, maxlength, is_required, validator_list)
  740
+        IntegerField.__init__(self, field_name, length, max_length, is_required, validator_list)
737 741
 
738 742
     def isSmallInteger(self, field_data, all_data):
739 743
         if not -32768 <= int(field_data) <= 32767:
740 744
             raise validators.CriticalValidationError, ugettext("Enter a whole number between -32,768 and 32,767.")
741 745
 
742 746
 class PositiveIntegerField(IntegerField):
743  
-    def __init__(self, field_name, length=10, maxlength=None, is_required=False, validator_list=None):
  747
+    def __init__(self, field_name, length=10, max_length=None, is_required=False, validator_list=None):
744 748
         if validator_list is None: validator_list = []
745 749
         validator_list = [self.isPositive] + validator_list
746  
-        IntegerField.__init__(self, field_name, length, maxlength, is_required, validator_list)
  750
+        IntegerField.__init__(self, field_name, length, max_length, is_required, validator_list)
747 751
 
748 752
     def isPositive(self, field_data, all_data):
749 753
         if int(field_data) < 0:
750 754
             raise validators.CriticalValidationError, ugettext("Enter a positive number.")
751 755
 
752 756
 class PositiveSmallIntegerField(IntegerField):
753  
-    def __init__(self, field_name, length=5, maxlength=None, is_required=False, validator_list=None):
  757
+    def __init__(self, field_name, length=5, max_length=None, is_required=False, validator_list=None):
754 758
         if validator_list is None: validator_list = []
755 759
         validator_list = [self.isPositiveSmall] + validator_list
756  
-        IntegerField.__init__(self, field_name, length, maxlength, is_required, validator_list)
  760
+        IntegerField.__init__(self, field_name, length, max_length, is_required, validator_list)
757 761
 
758 762
     def isPositiveSmall(self, field_data, all_data):
759 763
         if not 0 <= int(field_data) <= 32767:
760 764
             raise validators.CriticalValidationError, ugettext("Enter a whole number between 0 and 32,767.")
761 765
 
762 766
 class FloatField(TextField):
763  
-    def __init__(self, field_name, is_required=False, validator_list=None): 
764  
-        if validator_list is None: validator_list = [] 
765  
-        validator_list = [validators.isValidFloat] + validator_list 
766  
-        TextField.__init__(self, field_name, is_required=is_required, validator_list=validator_list) 
767  
- 
768  
-    def html2python(data): 
769  
-        if data == '' or data is None: 
770  
-            return None 
771  
-        return float(data) 
772  
-    html2python = staticmethod(html2python) 
773  
- 
774  
-class DecimalField(TextField): 
  767
+    def __init__(self, field_name, is_required=False, validator_list=None):
  768
+        if validator_list is None: validator_list = []
  769
+        validator_list = [validators.isValidFloat] + validator_list
  770
+        TextField.__init__(self, field_name, is_required=is_required, validator_list=validator_list)
  771
+
  772
+    def html2python(data):
  773
+        if data == '' or data is None:
  774
+            return None
  775
+        return float(data)
  776
+    html2python = staticmethod(html2python)
  777
+
  778
+class DecimalField(TextField):
775 779
     def __init__(self, field_name, max_digits, decimal_places, is_required=False, validator_list=None):
776 780
         if validator_list is None: validator_list = []
777 781
         self.max_digits, self.decimal_places = max_digits, decimal_places
778  
-        validator_list = [self.isValidDecimal] + validator_list 
779  
-        # Initialise the TextField, making sure it's large enough to fit the number with a - sign and a decimal point. 
780  
-        super(DecimalField, self).__init__(field_name, max_digits+2, max_digits+2, is_required, validator_list) 
  782
+        validator_list = [self.isValidDecimal] + validator_list
  783
+        # Initialise the TextField, making sure it's large enough to fit the number with a - sign and a decimal point.
  784
+        super(DecimalField, self).__init__(field_name, max_digits+2, max_digits+2, is_required, validator_list)
781 785
 
782  
-    def isValidDecimal(self, field_data, all_data): 
783  
-        v = validators.IsValidDecimal(self.max_digits, self.decimal_places) 
  786
+    def isValidDecimal(self, field_data, all_data):
  787
+        v = validators.IsValidDecimal(self.max_digits, self.decimal_places)
784 788
         try:
785 789
             v(field_data, all_data)
786 790
         except validators.ValidationError, e:
@@ -789,14 +793,14 @@ def isValidDecimal(self, field_data, all_data):
789 793
     def html2python(data):
790 794
         if data == '' or data is None:
791 795
             return None
792  
-        try: 
793  
-            import decimal 
  796
+        try:
  797
+            import decimal
794 798
         except ImportError:
795 799
             from django.utils import _decimal as decimal
796  
-        try: 
797  
-            return decimal.Decimal(data) 
798  
-        except decimal.InvalidOperation, e: 
799  
-            raise ValueError, e 
  800
+        try:
  801
+            return decimal.Decimal(data)
  802
+        except decimal.InvalidOperation, e:
  803
+            raise ValueError, e
800 804
     html2python = staticmethod(html2python)
801 805
 
802 806
 ####################
@@ -806,10 +810,10 @@ def html2python(data):
806 810
 class DatetimeField(TextField):
807 811
     """A FormField that automatically converts its data to a datetime.datetime object.
808 812
     The data should be in the format YYYY-MM-DD HH:MM:SS."""
809  
-    def __init__(self, field_name, length=30, maxlength=None, is_required=False, validator_list=None):
  813
+    def __init__(self, field_name, length=30, max_length=None, is_required=False, validator_list=None):
810 814
         if validator_list is None: validator_list = []
811 815
         self.field_name = field_name
812  
-        self.length, self.maxlength = length, maxlength
  816
+        self.length, self.max_length = length, max_length
813 817
         self.is_required = is_required
814 818
         self.validator_list = [validators.isValidANSIDatetime] + validator_list
815 819
 
@@ -836,7 +840,7 @@ class DateField(TextField):
836 840
     def __init__(self, field_name, is_required=False, validator_list=None):
837 841
         if validator_list is None: validator_list = []
838 842
         validator_list = [self.isValidDate] + validator_list
839  
-        TextField.__init__(self, field_name, length=10, maxlength=10,
  843
+        TextField.__init__(self, field_name, length=10, max_length=10,
840 844
             is_required=is_required, validator_list=validator_list)
841 845
 
842 846
     def isValidDate(self, field_data, all_data):
@@ -861,7 +865,7 @@ class TimeField(TextField):
861 865
     def __init__(self, field_name, is_required=False, validator_list=None):
862 866
         if validator_list is None: validator_list = []
863 867
         validator_list = [self.isValidTime] + validator_list
864  
-        TextField.__init__(self, field_name, length=8, maxlength=8,
  868
+        TextField.__init__(self, field_name, length=8, max_length=8,
865 869
             is_required=is_required, validator_list=validator_list)
866 870
 
867 871
     def isValidTime(self, field_data, all_data):
@@ -893,10 +897,10 @@ def html2python(data):
893 897
 
894 898
 class EmailField(TextField):
895 899
     "A convenience FormField for validating e-mail addresses"
896  
-    def __init__(self, field_name, length=50, maxlength=75, is_required=False, validator_list=None):
  900
+    def __init__(self, field_name, length=50, max_length=75, is_required=False, validator_list=None):
897 901
         if validator_list is None: validator_list = []
898 902
         validator_list = [self.isValidEmail] + validator_list
899  
-        TextField.__init__(self, field_name, length, maxlength=maxlength,
  903
+        TextField.__init__(self, field_name, length, max_length=max_length,
900 904
             is_required=is_required, validator_list=validator_list)
901 905
 
902 906
     def isValidEmail(self, field_data, all_data):
@@ -907,10 +911,10 @@ def isValidEmail(self, field_data, all_data):
907 911
 
908 912
 class URLField(TextField):
909 913
     "A convenience FormField for validating URLs"
910  
-    def __init__(self, field_name, length=50, maxlength=200, is_required=False, validator_list=None):
  914
+    def __init__(self, field_name, length=50, max_length=200, is_required=False, validator_list=None):
911 915
         if validator_list is None: validator_list = []
912 916
         validator_list = [self.isValidURL] + validator_list
913  
-        TextField.__init__(self, field_name, length=length, maxlength=maxlength,
  917
+        TextField.__init__(self, field_name, length=length, max_length=max_length,
914 918
             is_required=is_required, validator_list=validator_list)
915 919
 
916 920
     def isValidURL(self, field_data, all_data):
@@ -920,10 +924,10 @@ def isValidURL(self, field_data, all_data):
920 924
             raise validators.CriticalValidationError, e.messages
921 925
 
922 926
 class IPAddressField(TextField):
923  
-    def __init__(self, field_name, length=15, maxlength=15, is_required=False, validator_list=None):
  927
+    def __init__(self, field_name, length=15, max_length=15, is_required=False, validator_list=None):
924 928
         if validator_list is None: validator_list = []
925 929
         validator_list = [self.isValidIPAddress] + validator_list
926  
-        TextField.__init__(self, field_name, length=length, maxlength=maxlength,
  930
+        TextField.__init__(self, field_name, length=length, max_length=max_length,
927 931
             is_required=is_required, validator_list=validator_list)
928 932
 
929 933
     def isValidIPAddress(self, field_data, all_data):
@@ -970,7 +974,7 @@ class PhoneNumberField(TextField):
970 974
     def __init__(self, field_name, is_required=False, validator_list=None):
971 975
         if validator_list is None: validator_list = []
972 976
         validator_list = [self.isValidPhone] + validator_list
973  
-        TextField.__init__(self, field_name, length=12, maxlength=12,
  977
+        TextField.__init__(self, field_name, length=12, max_length=12,
974 978
             is_required=is_required, validator_list=validator_list)
975 979
 
976 980
     def isValidPhone(self, field_data, all_data):
@@ -984,7 +988,7 @@ class USStateField(TextField):
984 988
     def __init__(self, field_name, is_required=False, validator_list=None):
985 989
         if validator_list is None: validator_list = []
986 990
         validator_list = [self.isValidUSState] + validator_list
987  
-        TextField.__init__(self, field_name, length=2, maxlength=2,
  991
+        TextField.__init__(self, field_name, length=2, max_length=2,
988 992
             is_required=is_required, validator_list=validator_list)
989 993
 
990 994
     def isValidUSState(self, field_data, all_data):
@@ -1001,10 +1005,10 @@ def html2python(data):
1001 1005
 
1002 1006
 class CommaSeparatedIntegerField(TextField):
1003 1007
     "A convenience FormField for validating comma-separated integer fields"
1004  
-    def __init__(self, field_name, maxlength=None, is_required=False, validator_list=None):
  1008
+    def __init__(self, field_name, max_length=None, is_required=False, validator_list=None):
1005 1009
         if validator_list is None: validator_list = []
1006 1010
         validator_list = [self.isCommaSeparatedIntegerList] + validator_list
1007  
-        TextField.__init__(self, field_name, length=20, maxlength=maxlength,
  1011
+        TextField.__init__(self, field_name, length=20, max_length=max_length,
1008 1012
             is_required=is_required, validator_list=validator_list)
1009 1013
 
1010 1014
     def isCommaSeparatedIntegerList(self, field_data, all_data):
67  django/utils/maxlength.py
... ...
@@ -0,0 +1,67 @@
  1
+"""
  2
+Utilities for providing backwards compatibility for the maxlength argument,
  3
+which has been replaced by max_length, see ticket #2101.
  4
+"""
  5
+
  6
+from warnings import warn
  7
+
  8
+def get_maxlength(self):
  9
+    return self.max_length
  10
+
  11
+def set_maxlength(self, value):
  12
+    self.max_length = value
  13
+
  14
+def legacy_maxlength(max_length, maxlength):
  15
+    """
  16
+    Consolidates max_length and maxlength, providing backwards compatibilty
  17
+    for the legacy "maxlength" argument.
  18
+    If one of max_length or maxlength is given, then that value is returned.
  19
+    If both are given, a TypeError is raised.
  20
+    If maxlength is used at all, a deprecation warning is issued.
  21
+    """
  22
+    if maxlength is not None:
  23
+        warn("maxlength is deprecated, use max_length instead.",
  24
+             PendingDeprecationWarning,
  25
+             stacklevel=3)
  26
+        if max_length is not None:
  27
+            raise TypeError("field can not take both the max_length"
  28
+                            " argument and the legacy maxlength argument.")
  29
+        max_length = maxlength
  30
+    return max_length
  31
+
  32
+def remove_maxlength(func):
  33
+    """
  34
+    A decorator to be used on a class's __init__ that provides backwards
  35
+    compatibilty for the legacy "maxlength" keyword argument, i.e.
  36
+      name = models.CharField(maxlength=20)
  37
+    It does this by changing the passed "maxlength" keyword argument
  38
+    (if it exists) into a "max_length" keyword argument.
  39
+    """
  40
+    def inner(self, *args, **kwargs):
  41
+        max_length = kwargs.get('max_length', None)
  42
+        # pop maxlength because we don't want this going to __init__.
  43
+        maxlength = kwargs.pop('maxlength', None)
  44
+        max_length = legacy_maxlength(max_length, maxlength)
  45
+        # Only set the max_length keyword argument if we got a value back.
  46
+        if max_length is not None:
  47
+            kwargs['max_length'] = max_length
  48
+        func(self, *args, **kwargs)
  49
+    return inner
  50
+
  51
+# This metaclass is used in two places, and should be removed when legacy
  52
+# support for maxlength is dropped.
  53
+#   * oldforms.FormField
  54
+#   * db.models.fields.Field
  55
+
  56
+class LegacyMaxlength(type):
  57
+    """
  58
+    Metaclass for providing backwards compatibility support for the
  59
+    "maxlength" keyword argument.
  60
+    """
  61
+
  62
+    def __init__(cls, name, bases, attrs):
  63
+        super(LegacyMaxlength, cls).__init__(name, bases, attrs)
  64
+        # Decorate the class's __init__ to remove any maxlength keyword.
  65
+        cls.__init__ = remove_maxlength(cls.__init__)
  66
+        # Support accessing and setting to the legacy maxlength attribute.
  67
+        cls.maxlength = property(get_maxlength, set_maxlength)
20  docs/contributing.txt
@@ -340,14 +340,14 @@ Model style
340 340
       Do this::
341 341
 
342 342
           class Person(models.Model):
343  
-              first_name = models.CharField(maxlength=20)
344  
-              last_name = models.CharField(maxlength=40)
  343
+              first_name = models.CharField(max_length=20)
  344
+              last_name = models.CharField(max_length=40)
345 345
 
346 346
       Don't do this::
347 347
 
348 348
           class Person(models.Model):
349  
-              FirstName = models.CharField(maxlength=20)
350  
-              Last_Name = models.CharField(maxlength=40)
  349
+              FirstName = models.CharField(max_length=20)
  350
+              Last_Name = models.CharField(max_length=40)
351 351
 
352 352
     * The ``class Meta`` should appear *after* the fields are defined, with
353 353
       a single blank line separating the fields and the class definition.
@@ -355,8 +355,8 @@ Model style
355 355
       Do this::
356 356
 
357 357
           class Person(models.Model):
358  
-              first_name = models.CharField(maxlength=20)
359  
-              last_name = models.CharField(maxlength=40)
  358
+              first_name = models.CharField(max_length=20)
  359
+              last_name = models.CharField(max_length=40)
360 360
 
361 361
               class Meta:
362 362
                   verbose_name_plural = 'people'
@@ -364,8 +364,8 @@ Model style
364 364
       Don't do this::
365 365
 
366 366
           class Person(models.Model):
367  
-              first_name = models.CharField(maxlength=20)
368  
-              last_name = models.CharField(maxlength=40)
  367
+              first_name = models.CharField(max_length=20)
  368
+              last_name = models.CharField(max_length=40)
369 369
               class Meta:
370 370
                   verbose_name_plural = 'people'
371 371
 
@@ -375,8 +375,8 @@ Model style
375 375
               class Meta:
376 376
                   verbose_name_plural = 'people'
377 377
 
378  
-              first_name = models.CharField(maxlength=20)
379  
-              last_name = models.CharField(maxlength=40)
  378
+              first_name = models.CharField(max_length=20)
  379
+              last_name = models.CharField(max_length=40)
380 380
 
381 381
     * The order of model inner classes and standard methods should be as
382 382
       follows (noting that these are not all required):
10  docs/db-api.txt
@@ -12,14 +12,14 @@ Throughout this reference, we'll refer to the following models, which comprise
12 12
 a weblog application::
13 13
 
14 14
     class Blog(models.Model):
15  
-        name = models.CharField(maxlength=100)
  15
+        name = models.CharField(max_length=100)
16 16
         tagline = models.TextField()
17 17
 
18 18
         def __unicode__(self):
19 19
             return self.name
20 20
 
21 21
     class Author(models.Model):
22  
-        name = models.CharField(maxlength=50)
  22
+        name = models.CharField(max_length=50)
23 23
         email = models.EmailField()
24 24
 
25 25
         def __unicode__(self):
@@ -27,7 +27,7 @@ a weblog application::
27 27
 
28 28
     class Entry(models.Model):
29 29
         blog = models.ForeignKey(Blog)
30  
-        headline = models.CharField(maxlength=255)
  30
+        headline = models.CharField(max_length=255)
31 31
         body_text = models.TextField()
32 32
         pub_date = models.DateTimeField()
33 33
         authors = models.ManyToManyField(Author)
@@ -1806,8 +1806,8 @@ following model::
1806 1806
         ('F', 'Female'),
1807 1807
     )
1808 1808
     class Person(models.Model):
1809  
-        name = models.CharField(maxlength=20)
1810  
-        gender = models.CharField(maxlength=1, choices=GENDER_CHOICES)
  1809
+        name = models.CharField(max_length=20)
  1810
+        gender = models.CharField(max_length=1, choices=GENDER_CHOICES)
1811 1811
 
1812 1812
 ...each ``Person`` instance will have a ``get_gender_display()`` method. Example::
1813 1813
 
10  docs/forms.txt
@@ -37,11 +37,11 @@ this document, we'll be working with the following model, a "place" object::
37 37
     )
38 38
 
39 39
     class Place(models.Model):
40  
-        name = models.CharField(maxlength=100)
41  
-        address = models.CharField(maxlength=100, blank=True)
42  
-        city = models.CharField(maxlength=50, blank=True)
  40
+        name = models.CharField(max_length=100)
  41
+        address = models.CharField(max_length=100, blank=True)
  42
+        city = models.CharField(max_length=50, blank=True)
43 43
         state = models.USStateField()
44  
-        zip_code = models.CharField(maxlength=5, blank=True)
  44
+        zip_code = models.CharField(max_length=5, blank=True)
45 45
         place_type = models.IntegerField(choices=PLACE_TYPES)
46 46
 
47 47
         class Admin:
@@ -388,7 +388,7 @@ for a "contact" form on a website::
388 388
         def __init__(self):
389 389
             self.fields = (
390 390
                 forms.EmailField(field_name="from", is_required=True),
391  
-                forms.TextField(field_name="subject", length=30, maxlength=200, is_required=True),
  391
+                forms.TextField(field_name="subject", length=30, max_length=200, is_required=True),
392 392
                 forms.SelectField(field_name="urgency", choices=urgency_choices),
393 393
                 forms.LargeTextField(field_name="contents", is_required=True),
394 394
             )
110  docs/model-api.txt
@@ -33,8 +33,8 @@ This example model defines a ``Person``, which has a ``first_name`` and
33 33
     from django.db import models
34 34
 
35 35
     class Person(models.Model):
36  
-        first_name = models.CharField(maxlength=30)
37  
-        last_name = models.CharField(maxlength=30)
  36
+        first_name = models.CharField(max_length=30)
  37
+        last_name = models.CharField(max_length=30)
38 38
 
39 39
 ``first_name`` and ``last_name`` are *fields* of the model. Each field is
40 40
 specified as a class attribute, and each attribute maps to a database column.
@@ -69,13 +69,13 @@ attributes.
69 69
 Example::
70 70
 
71 71
     class Musician(models.Model):
72  
-        first_name = models.CharField(maxlength=50)
73  
-        last_name = models.CharField(maxlength=50)
74  
-        instrument = models.CharField(maxlength=100)
  72
+        first_name = models.CharField(max_length=50)
  73
+        last_name = models.CharField(max_length=50)
  74
+        instrument = models.CharField(max_length=100)
75 75
 
76 76
     class Album(models.Model):
77 77
         artist = models.ForeignKey(Musician)
78  
-        name = models.CharField(maxlength=100)
  78
+        name = models.CharField(max_length=100)
79 79
         release_date = models.DateField()
80 80
         num_stars = models.IntegerField()
81 81
 
@@ -142,14 +142,18 @@ For large amounts of text, use ``TextField``.
142 142
 
143 143
 The admin represents this as an ``<input type="text">`` (a single-line input).
144 144
 
145  
-``CharField`` has an extra required argument, ``maxlength``, the maximum length
146  
-(in characters) of the field. The maxlength is enforced at the database level
  145
+``CharField`` has an extra required argument, ``max_length``, the maximum length
  146
+(in characters) of the field. The max_length is enforced at the database level
147 147
 and in Django's validation.
148 148
 
149  
-``CommaSeparatedIntegerField``
  149
+Django veterans: Note that the argument is now called ``max_length`` to
  150
+provide consistency throughout Django. There is full legacy support for
  151
+the old ``maxlength`` argument, but ``max_length`` is prefered.
  152
+	
  153
+ ``CommaSeparatedIntegerField``
150 154
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~