Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
@gdub gdub authored
Showing with 647 additions and 407 deletions.
  1. +1 −1  django/contrib/admin/models.py
  2. +1 −1  django/contrib/admin/templatetags/admin_modify.py
  3. +2 −2 django/contrib/admin/views/doc.py
  4. +10 −10 django/contrib/auth/forms.py
  5. +7 −7 django/contrib/auth/models.py
  6. +4 −4 django/contrib/comments/models.py
  7. +3 −3 django/contrib/comments/views/comments.py
  8. +3 −3 django/contrib/contenttypes/models.py
  9. +3 −3 django/contrib/flatpages/models.py
  10. +2 −2 django/contrib/redirects/models.py
  11. +1 −1  django/contrib/sessions/models.py
  12. +2 −2 django/contrib/sites/models.py
  13. +8 −8 django/core/management.py
  14. +3 −3 django/db/backends/ado_mssql/creation.py
  15. +3 −3 django/db/backends/mysql/creation.py
  16. +3 −3 django/db/backends/mysql_old/creation.py
  17. +2 −2 django/db/backends/oracle/creation.py
  18. +3 −3 django/db/backends/postgresql/creation.py
  19. +3 −3 django/db/backends/sqlite3/creation.py
  20. +1 −1  django/db/backends/sqlite3/introspection.py
  21. +13 −9 django/db/models/fields/__init__.py
  22. +1 −0  django/newforms/fields.py
  23. +60 −56 django/oldforms/__init__.py
  24. +67 −0 django/utils/maxlength.py
  25. +10 −10 docs/contributing.txt
  26. +5 −5 docs/db-api.txt
  27. +5 −5 docs/forms.txt
  28. +57 −53 docs/model-api.txt
  29. +4 −4 docs/newforms.txt
  30. +3 −3 docs/overview.txt
  31. +4 −4 docs/sites.txt
  32. +2 −2 docs/testing.txt
  33. +3 −3 docs/tutorial01.txt
  34. +1 −1  docs/tutorial02.txt
  35. +1 −1  tests/modeltests/basic/models.py
  36. +2 −2 tests/modeltests/choices/models.py
  37. +3 −3 tests/modeltests/custom_columns/models.py
  38. +5 −5 tests/modeltests/custom_managers/models.py
  39. +1 −1  tests/modeltests/custom_methods/models.py
  40. +4 −4 tests/modeltests/custom_pk/models.py
  41. +1 −1  tests/modeltests/field_defaults/models.py
  42. +1 −1  tests/modeltests/fixtures/models.py
  43. +4 −4 tests/modeltests/generic_relations/models.py
  44. +2 −2 tests/modeltests/get_latest/models.py
  45. +2 −2 tests/modeltests/get_object_or_404/models.py
  46. +2 −2 tests/modeltests/get_or_create/models.py
  47. +22 −22 tests/modeltests/invalid_models/models.py
  48. +1 −1  tests/modeltests/lookup/models.py
  49. +1 −1  tests/modeltests/m2m_and_m2o/models.py
  50. +4 −4 tests/modeltests/m2m_intermediary/models.py
  51. +2 −2 tests/modeltests/m2m_multiple/models.py
  52. +1 −1  tests/modeltests/m2m_recursive/models.py
  53. +1 −1  tests/modeltests/m2o_recursive/models.py
  54. +1 −1  tests/modeltests/m2o_recursive2/models.py
  55. +3 −3 tests/modeltests/manipulators/models.py
  56. +2 −2 tests/modeltests/many_to_many/models.py
  57. +3 −3 tests/modeltests/many_to_one/models.py
  58. +2 −2 tests/modeltests/many_to_one_null/models.py
  59. +5 −5 tests/modeltests/model_forms/models.py
  60. +2 −2 tests/modeltests/model_inheritance/models.py
  61. +2 −2 tests/modeltests/mutually_referential/models.py
  62. +6 −6 tests/modeltests/one_to_one/models.py
  63. +1 −1  tests/modeltests/or_lookups/models.py
  64. +1 −1  tests/modeltests/ordering/models.py
  65. +1 −1  tests/modeltests/pagination/models.py
  66. +2 −2 tests/modeltests/properties/models.py
  67. +8 −8 tests/modeltests/reserved_names/models.py
  68. +3 −3 tests/modeltests/reverse_lookup/models.py
  69. +2 −2 tests/modeltests/save_delete_hooks/models.py
  70. +8 −8 tests/modeltests/select_related/models.py
  71. +3 −3 tests/modeltests/serializers/models.py
  72. +2 −2 tests/modeltests/str/models.py
  73. +2 −2 tests/modeltests/transactions/models.py
  74. +1 −1  tests/modeltests/validation/models.py
  75. +1 −1  tests/regressiontests/bug639/models.py
  76. +1 −1  tests/regressiontests/datatypes/models.py
  77. +4 −4 tests/regressiontests/fixtures_regress/models.py
  78. +1 −1  tests/regressiontests/initial_sql_regress/models.py
  79. +37 −37 tests/regressiontests/invalid_admin_options/models.py
  80. +3 −3 tests/regressiontests/many_to_one_regress/models.py
  81. 0  tests/regressiontests/maxlength/__init__.py
  82. 0  tests/regressiontests/maxlength/models.py
  83. +160 −0 tests/regressiontests/maxlength/tests.py
  84. +1 −1  tests/regressiontests/model_regress/models.py
  85. +2 −2 tests/regressiontests/null_queries/models.py
  86. +3 −3 tests/regressiontests/one_to_one_regress/models.py
  87. +8 −8 tests/regressiontests/serializers_regress/models.py
  88. +6 −6 tests/regressiontests/string_lookup/models.py
View
2  django/contrib/admin/models.py
@@ -18,7 +18,7 @@ class LogEntry(models.Model):
user = models.ForeignKey(User)
content_type = models.ForeignKey(ContentType, blank=True, null=True)
object_id = models.TextField(_('object id'), blank=True, null=True)
- object_repr = models.CharField(_('object repr'), maxlength=200)
+ object_repr = models.CharField(_('object repr'), max_length=200)
action_flag = models.PositiveSmallIntegerField(_('action flag'))
change_message = models.TextField(_('change message'), blank=True)
objects = LogEntryManager()
View
2  django/contrib/admin/templatetags/admin_modify.py
@@ -192,7 +192,7 @@ def auto_populated_field_script(auto_pop_fields, change = False):
t.append(u'document.getElementById("id_%s").onkeyup = function() {' \
' var e = document.getElementById("id_%s");' \
' if(!e._changed) { e.value = URLify(%s, %s);} }; ' % (
- f, field.name, add_values, field.maxlength))
+ f, field.name, add_values, field.max_length))
return u''.join(t)
auto_populated_field_script = register.simple_tag(auto_populated_field_script)
View
4 django/contrib/admin/views/doc.py
@@ -291,7 +291,7 @@ def get_return_data_type(func_name):
DATA_TYPE_MAPPING = {
'AutoField' : _('Integer'),
'BooleanField' : _('Boolean (Either True or False)'),
- 'CharField' : _('String (up to %(maxlength)s)'),
+ 'CharField' : _('String (up to %(max_length)s)'),
'CommaSeparatedIntegerField': _('Comma-separated integers'),
'DateField' : _('Date (without time)'),
'DateTimeField' : _('Date (with time)'),
@@ -310,7 +310,7 @@ def get_return_data_type(func_name):
'PhoneNumberField' : _('Phone number'),
'PositiveIntegerField' : _('Integer'),
'PositiveSmallIntegerField' : _('Integer'),
- 'SlugField' : _('String (up to %(maxlength)s)'),
+ 'SlugField' : _('String (up to %(max_length)s)'),
'SmallIntegerField' : _('Integer'),
'TextField' : _('Text'),
'TimeField' : _('Time'),
View
20 django/contrib/auth/forms.py
@@ -10,10 +10,10 @@ class UserCreationForm(oldforms.Manipulator):
"A form that creates a user, with no privileges, from the given username and password."
def __init__(self):
self.fields = (
- oldforms.TextField(field_name='username', length=30, maxlength=30, is_required=True,
+ oldforms.TextField(field_name='username', length=30, max_length=30, is_required=True,
validator_list=[validators.isAlphaNumeric, self.isValidUsername]),
- oldforms.PasswordField(field_name='password1', length=30, maxlength=60, is_required=True),
- oldforms.PasswordField(field_name='password2', length=30, maxlength=60, is_required=True,
+ oldforms.PasswordField(field_name='password1', length=30, max_length=60, is_required=True),
+ oldforms.PasswordField(field_name='password2', length=30, max_length=60, is_required=True,
validator_list=[validators.AlwaysMatchesOtherField('password1', _("The two password fields didn't match."))]),
)
@@ -42,9 +42,9 @@ def __init__(self, request=None):
"""
self.request = request
self.fields = [
- oldforms.TextField(field_name="username", length=15, maxlength=30, is_required=True,
+ oldforms.TextField(field_name="username", length=15, max_length=30, is_required=True,
validator_list=[self.isValidUser, self.hasCookiesEnabled]),
- oldforms.PasswordField(field_name="password", length=15, maxlength=30, is_required=True),
+ oldforms.PasswordField(field_name="password", length=15, max_length=30, is_required=True),
]
self.user_cache = None
@@ -111,11 +111,11 @@ class PasswordChangeForm(oldforms.Manipulator):
def __init__(self, user):
self.user = user
self.fields = (
- oldforms.PasswordField(field_name="old_password", length=30, maxlength=30, is_required=True,
+ oldforms.PasswordField(field_name="old_password", length=30, max_length=30, is_required=True,
validator_list=[self.isValidOldPassword]),
- oldforms.PasswordField(field_name="new_password1", length=30, maxlength=30, is_required=True,
+ oldforms.PasswordField(field_name="new_password1", length=30, max_length=30, is_required=True,
validator_list=[validators.AlwaysMatchesOtherField('new_password2', _("The two 'new password' fields didn't match."))]),
- oldforms.PasswordField(field_name="new_password2", length=30, maxlength=30, is_required=True),
+ oldforms.PasswordField(field_name="new_password2", length=30, max_length=30, is_required=True),
)
def isValidOldPassword(self, new_data, all_data):
@@ -133,8 +133,8 @@ class AdminPasswordChangeForm(oldforms.Manipulator):
def __init__(self, user):
self.user = user
self.fields = (
- oldforms.PasswordField(field_name='password1', length=30, maxlength=60, is_required=True),
- oldforms.PasswordField(field_name='password2', length=30, maxlength=60, is_required=True,
+ oldforms.PasswordField(field_name='password1', length=30, max_length=60, is_required=True),
+ oldforms.PasswordField(field_name='password2', length=30, max_length=60, is_required=True,
validator_list=[validators.AlwaysMatchesOtherField('password1', _("The two password fields didn't match."))]),
)
View
14 django/contrib/auth/models.py
@@ -50,9 +50,9 @@ class Permission(models.Model):
Three basic permissions -- add, change and delete -- are automatically created for each Django model.
"""
- name = models.CharField(_('name'), maxlength=50)
+ name = models.CharField(_('name'), max_length=50)
content_type = models.ForeignKey(ContentType)
- codename = models.CharField(_('codename'), maxlength=100)
+ codename = models.CharField(_('codename'), max_length=100)
class Meta:
verbose_name = _('permission')
@@ -70,7 +70,7 @@ class Group(models.Model):
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.
"""
- name = models.CharField(_('name'), maxlength=80, unique=True)
+ name = models.CharField(_('name'), max_length=80, unique=True)
permissions = models.ManyToManyField(Permission, verbose_name=_('permissions'), blank=True, filter_interface=models.HORIZONTAL)
class Meta:
@@ -108,11 +108,11 @@ class User(models.Model):
Username and password are required. Other fields are optional.
"""
- 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)."))
- first_name = models.CharField(_('first name'), maxlength=30, blank=True)
- last_name = models.CharField(_('last name'), maxlength=30, blank=True)
+ 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)."))
+ first_name = models.CharField(_('first name'), max_length=30, blank=True)
+ last_name = models.CharField(_('last name'), max_length=30, blank=True)
email = models.EmailField(_('e-mail address'), blank=True)
- password = models.CharField(_('password'), maxlength=128, help_text=_("Use '[algo]$[salt]$[hexdigest]' or use the <a href=\"password/\">change password form</a>."))
+ password = models.CharField(_('password'), max_length=128, help_text=_("Use '[algo]$[salt]$[hexdigest]' or use the <a href=\"password/\">change password form</a>."))
is_staff = models.BooleanField(_('staff status'), default=False, help_text=_("Designates whether the user can log into this admin site."))
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."))
is_superuser = models.BooleanField(_('superuser status'), default=False, help_text=_("Designates that this user has all permissions without explicitly assigning them."))
View
8 django/contrib/comments/models.py
@@ -65,8 +65,8 @@ class Comment(models.Model):
user = models.ForeignKey(User, raw_id_admin=True)
content_type = models.ForeignKey(ContentType)
object_id = models.IntegerField(_('object ID'))
- headline = models.CharField(_('headline'), maxlength=255, blank=True)
- comment = models.TextField(_('comment'), maxlength=3000)
+ headline = models.CharField(_('headline'), max_length=255, blank=True)
+ comment = models.TextField(_('comment'), max_length=3000)
rating1 = models.PositiveSmallIntegerField(_('rating #1'), blank=True, null=True)
rating2 = models.PositiveSmallIntegerField(_('rating #2'), blank=True, null=True)
rating3 = models.PositiveSmallIntegerField(_('rating #3'), blank=True, null=True)
@@ -164,8 +164,8 @@ class FreeComment(models.Model):
# A FreeComment is a comment by a non-registered user.
content_type = models.ForeignKey(ContentType)
object_id = models.IntegerField(_('object ID'))
- comment = models.TextField(_('comment'), maxlength=3000)
- person_name = models.CharField(_("person's name"), maxlength=50)
+ comment = models.TextField(_('comment'), max_length=3000)
+ person_name = models.CharField(_("person's name"), max_length=50)
submit_date = models.DateTimeField(_('date/time submitted'), auto_now_add=True)
is_public = models.BooleanField(_('is public'))
ip_address = models.IPAddressField(_('ip address'))
View
6 django/contrib/comments/views/comments.py
@@ -29,7 +29,7 @@ def get_validator_list(rating_num):
else:
return []
self.fields.extend([
- oldforms.LargeTextField(field_name="comment", maxlength=3000, is_required=True,
+ oldforms.LargeTextField(field_name="comment", max_length=3000, is_required=True,
validator_list=[self.hasNoProfanities]),
oldforms.RadioSelectField(field_name="rating1", choices=choices,
is_required=ratings_required and num_rating_choices > 0,
@@ -122,9 +122,9 @@ class PublicFreeCommentManipulator(oldforms.Manipulator):
"Manipulator that handles public free (unregistered) comments"
def __init__(self):
self.fields = (
- oldforms.TextField(field_name="person_name", maxlength=50, is_required=True,
+ oldforms.TextField(field_name="person_name", max_length=50, is_required=True,
validator_list=[self.hasNoProfanities]),
- oldforms.LargeTextField(field_name="comment", maxlength=3000, is_required=True,
+ oldforms.LargeTextField(field_name="comment", max_length=3000, is_required=True,
validator_list=[self.hasNoProfanities]),
)
View
6 django/contrib/contenttypes/models.py
@@ -32,9 +32,9 @@ def clear_cache(self):
CONTENT_TYPE_CACHE = {}
class ContentType(models.Model):
- name = models.CharField(maxlength=100)
- app_label = models.CharField(maxlength=100)
- model = models.CharField(_('python model class name'), maxlength=100)
+ name = models.CharField(max_length=100)
+ app_label = models.CharField(max_length=100)
+ model = models.CharField(_('python model class name'), max_length=100)
objects = ContentTypeManager()
class Meta:
verbose_name = _('content type')
View
6 django/contrib/flatpages/models.py
@@ -4,12 +4,12 @@
from django.utils.translation import ugettext_lazy as _
class FlatPage(models.Model):
- url = models.CharField(_('URL'), maxlength=100, validator_list=[validators.isAlphaNumericURL], db_index=True,
+ url = models.CharField(_('URL'), max_length=100, validator_list=[validators.isAlphaNumericURL], db_index=True,
help_text=_("Example: '/about/contact/'. Make sure to have leading and trailing slashes."))
- title = models.CharField(_('title'), maxlength=200)
+ title = models.CharField(_('title'), max_length=200)
content = models.TextField(_('content'))
enable_comments = models.BooleanField(_('enable comments'))
- template_name = models.CharField(_('template name'), maxlength=70, blank=True,
+ template_name = models.CharField(_('template name'), max_length=70, blank=True,
help_text=_("Example: 'flatpages/contact_page.html'. If this isn't provided, the system will use 'flatpages/default.html'."))
registration_required = models.BooleanField(_('registration required'), help_text=_("If this is checked, only logged-in users will be able to view the page."))
sites = models.ManyToManyField(Site)
View
4 django/contrib/redirects/models.py
@@ -4,9 +4,9 @@
class Redirect(models.Model):
site = models.ForeignKey(Site, radio_admin=models.VERTICAL)
- old_path = models.CharField(_('redirect from'), maxlength=200, db_index=True,
+ old_path = models.CharField(_('redirect from'), max_length=200, db_index=True,
help_text=_("This should be an absolute path, excluding the domain name. Example: '/events/search/'."))
- new_path = models.CharField(_('redirect to'), maxlength=200, blank=True,
+ new_path = models.CharField(_('redirect to'), max_length=200, blank=True,
help_text=_("This can be either an absolute path (as above) or a full URL starting with 'http://'."))
class Meta:
View
2  django/contrib/sessions/models.py
@@ -65,7 +65,7 @@ class Session(models.Model):
the sessions documentation that is shipped with Django (also available
on the Django website).
"""
- session_key = models.CharField(_('session key'), maxlength=40, primary_key=True)
+ session_key = models.CharField(_('session key'), max_length=40, primary_key=True)
session_data = models.TextField(_('session data'))
expire_date = models.DateTimeField(_('expire date'))
objects = SessionManager()
View
4 django/contrib/sites/models.py
@@ -12,8 +12,8 @@ def get_current(self):
return self.get(pk=sid)
class Site(models.Model):
- domain = models.CharField(_('domain name'), maxlength=100)
- name = models.CharField(_('display name'), maxlength=50)
+ domain = models.CharField(_('domain name'), max_length=100)
+ name = models.CharField(_('display name'), max_length=50)
objects = SiteManager()
class Meta:
db_table = 'django_site'
View
16 django/core/management.py
@@ -910,9 +910,9 @@ def inspectdb():
field_type, new_params = field_type
extra_params.update(new_params)
- # Add maxlength for all CharFields.
+ # Add max_length for all CharFields.
if field_type == 'CharField' and row[3]:
- extra_params['maxlength'] = row[3]
+ extra_params['max_length'] = row[3]
if field_type == 'DecimalField':
extra_params['max_digits'] = row[4]
@@ -987,8 +987,8 @@ def get_validation_errors(outfile, app=None):
for f in opts.fields:
if f.name == 'id' and not f.primary_key and opts.pk.name == 'id':
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)
- if isinstance(f, models.CharField) and f.maxlength in (None, 0):
- e.add(opts, '"%s": CharFields require a "maxlength" attribute.' % f.name)
+ if isinstance(f, models.CharField) and f.max_length in (None, 0):
+ e.add(opts, '"%s": CharFields require a "max_length" attribute.' % f.name)
if isinstance(f, models.DecimalField):
if f.decimal_places is None:
e.add(opts, '"%s": DecimalFields require a "decimal_places" attribute.' % f.name)
@@ -1013,11 +1013,11 @@ def get_validation_errors(outfile, app=None):
if f.db_index not in (None, True, False):
e.add(opts, '"%s": "db_index" should be either None, True or False.' % f.name)
- # Check that maxlength <= 255 if using older MySQL versions.
+ # Check that max_length <= 255 if using older MySQL versions.
if settings.DATABASE_ENGINE == 'mysql':
db_version = connection.get_server_version()
- if db_version < (5, 0, 3) and isinstance(f, (models.CharField, models.CommaSeparatedIntegerField, models.SlugField)) and f.maxlength > 255:
- 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]])))
+ if db_version < (5, 0, 3) and isinstance(f, (models.CharField, models.CommaSeparatedIntegerField, models.SlugField)) and f.max_length > 255:
+ 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]])))
# Check to see if the related field will clash with any
# existing fields, m2m fields, m2m related objects or related objects
@@ -1252,7 +1252,7 @@ def createcachetable(tablename):
from django.db import backend, connection, transaction, models
fields = (
# "key" is a reserved word in MySQL, so use "cache_key" instead.
- models.CharField(name='cache_key', maxlength=255, unique=True, primary_key=True),
+ models.CharField(name='cache_key', max_length=255, unique=True, primary_key=True),
models.TextField(name='value'),
models.DateTimeField(name='expires', db_index=True),
)
View
6 django/db/backends/ado_mssql/creation.py
@@ -1,8 +1,8 @@
DATA_TYPES = {
'AutoField': 'int IDENTITY (1, 1)',
'BooleanField': 'bit',
- 'CharField': 'varchar(%(maxlength)s)',
- 'CommaSeparatedIntegerField': 'varchar(%(maxlength)s)',
+ 'CharField': 'varchar(%(max_length)s)',
+ 'CommaSeparatedIntegerField': 'varchar(%(max_length)s)',
'DateField': 'smalldatetime',
'DateTimeField': 'smalldatetime',
'DecimalField': 'numeric(%(max_digits)s, %(decimal_places)s)',
@@ -17,7 +17,7 @@
'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(%(maxlength)s)',
+ 'SlugField': 'varchar(%(max_length)s)',
'SmallIntegerField': 'smallint',
'TextField': 'text',
'TimeField': 'time',
View
6 django/db/backends/mysql/creation.py
@@ -5,8 +5,8 @@
DATA_TYPES = {
'AutoField': 'integer AUTO_INCREMENT',
'BooleanField': 'bool',
- 'CharField': 'varchar(%(maxlength)s)',
- 'CommaSeparatedIntegerField': 'varchar(%(maxlength)s)',
+ 'CharField': 'varchar(%(max_length)s)',
+ 'CommaSeparatedIntegerField': 'varchar(%(max_length)s)',
'DateField': 'date',
'DateTimeField': 'datetime',
'DecimalField': 'numeric(%(max_digits)s, %(decimal_places)s)',
@@ -21,7 +21,7 @@
'PhoneNumberField': 'varchar(20)',
'PositiveIntegerField': 'integer UNSIGNED',
'PositiveSmallIntegerField': 'smallint UNSIGNED',
- 'SlugField': 'varchar(%(maxlength)s)',
+ 'SlugField': 'varchar(%(max_length)s)',
'SmallIntegerField': 'smallint',
'TextField': 'longtext',
'TimeField': 'time',
View
6 django/db/backends/mysql_old/creation.py
@@ -5,8 +5,8 @@
DATA_TYPES = {
'AutoField': 'integer AUTO_INCREMENT',
'BooleanField': 'bool',
- 'CharField': 'varchar(%(maxlength)s)',
- 'CommaSeparatedIntegerField': 'varchar(%(maxlength)s)',
+ 'CharField': 'varchar(%(max_length)s)',
+ 'CommaSeparatedIntegerField': 'varchar(%(max_length)s)',
'DateField': 'date',
'DateTimeField': 'datetime',
'DecimalField': 'numeric(%(max_digits)s, %(decimal_places)s)',
@@ -21,7 +21,7 @@
'PhoneNumberField': 'varchar(20)',
'PositiveIntegerField': 'integer UNSIGNED',
'PositiveSmallIntegerField': 'smallint UNSIGNED',
- 'SlugField': 'varchar(%(maxlength)s)',
+ 'SlugField': 'varchar(%(max_length)s)',
'SmallIntegerField': 'smallint',
'TextField': 'longtext',
'TimeField': 'time',
View
4 django/db/backends/oracle/creation.py
@@ -8,8 +8,8 @@
DATA_TYPES = {
'AutoField': 'NUMBER(11)',
'BooleanField': 'NUMBER(1) CHECK (%(column)s IN (0,1))',
- 'CharField': 'NVARCHAR2(%(maxlength)s)',
- 'CommaSeparatedIntegerField': 'VARCHAR2(%(maxlength)s)',
+ 'CharField': 'NVARCHAR2(%(max_length)s)',
+ 'CommaSeparatedIntegerField': 'VARCHAR2(%(max_length)s)',
'DateField': 'DATE',
'DateTimeField': 'TIMESTAMP',
'DecimalField': 'NUMBER(%(max_digits)s, %(decimal_places)s)',
View
6 django/db/backends/postgresql/creation.py
@@ -5,8 +5,8 @@
DATA_TYPES = {
'AutoField': 'serial',
'BooleanField': 'boolean',
- 'CharField': 'varchar(%(maxlength)s)',
- 'CommaSeparatedIntegerField': 'varchar(%(maxlength)s)',
+ 'CharField': 'varchar(%(max_length)s)',
+ 'CommaSeparatedIntegerField': 'varchar(%(max_length)s)',
'DateField': 'date',
'DateTimeField': 'timestamp with time zone',
'DecimalField': 'numeric(%(max_digits)s, %(decimal_places)s)',
@@ -21,7 +21,7 @@
'PhoneNumberField': 'varchar(20)',
'PositiveIntegerField': 'integer CHECK ("%(column)s" >= 0)',
'PositiveSmallIntegerField': 'smallint CHECK ("%(column)s" >= 0)',
- 'SlugField': 'varchar(%(maxlength)s)',
+ 'SlugField': 'varchar(%(max_length)s)',
'SmallIntegerField': 'smallint',
'TextField': 'text',
'TimeField': 'time',
View
6 django/db/backends/sqlite3/creation.py
@@ -4,8 +4,8 @@
DATA_TYPES = {
'AutoField': 'integer',
'BooleanField': 'bool',
- 'CharField': 'varchar(%(maxlength)s)',
- 'CommaSeparatedIntegerField': 'varchar(%(maxlength)s)',
+ 'CharField': 'varchar(%(max_length)s)',
+ 'CommaSeparatedIntegerField': 'varchar(%(max_length)s)',
'DateField': 'date',
'DateTimeField': 'datetime',
'DecimalField': 'decimal',
@@ -20,7 +20,7 @@
'PhoneNumberField': 'varchar(20)',
'PositiveIntegerField': 'integer unsigned',
'PositiveSmallIntegerField': 'smallint unsigned',
- 'SlugField': 'varchar(%(maxlength)s)',
+ 'SlugField': 'varchar(%(max_length)s)',
'SmallIntegerField': 'smallint',
'TextField': 'text',
'TimeField': 'time',
View
2  django/db/backends/sqlite3/introspection.py
@@ -81,7 +81,7 @@ def __getitem__(self, key):
import re
m = re.search(r'^\s*(?:var)?char\s*\(\s*(\d+)\s*\)\s*$', key)
if m:
- return ('CharField', {'maxlength': int(m.group(1))})
+ return ('CharField', {'max_length': int(m.group(1))})
raise KeyError
DATA_TYPES_REVERSE = FlexibleFieldLookupDict()
View
22 django/db/models/fields/__init__.py
@@ -11,6 +11,7 @@
from django.utils.text import capfirst
from django.utils.translation import ugettext_lazy, ugettext as _
from django.utils.encoding import smart_unicode, force_unicode, smart_str
+from django.utils.maxlength import LegacyMaxlength
import datetime, os, time
try:
import decimal
@@ -63,6 +64,9 @@ def manipulator_validator_unique(f, opts, self, field_data, all_data):
# getattr(obj, opts.pk.attname)
class Field(object):
+ # Provide backwards compatibility for the maxlength attribute and
+ # argument for this class and all subclasses.
+ __metaclass__ = LegacyMaxlength
# Designates whether empty strings fundamentally are allowed at the
# database level.
@@ -72,7 +76,7 @@ class Field(object):
creation_counter = 0
def __init__(self, verbose_name=None, name=None, primary_key=False,
- maxlength=None, unique=False, blank=False, null=False, db_index=False,
+ max_length=None, unique=False, blank=False, null=False, db_index=False,
core=False, rel=None, default=NOT_PROVIDED, editable=True, serialize=True,
prepopulate_from=None, unique_for_date=None, unique_for_month=None,
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,
self.name = name
self.verbose_name = verbose_name
self.primary_key = primary_key
- self.maxlength, self.unique = maxlength, unique
+ self.max_length, self.unique = max_length, unique
self.blank, self.null = blank, null
# Oracle treats the empty string ('') as null, so coerce the null
# option whenever '' is a possible value.
@@ -244,8 +248,8 @@ def get_manipulator_field_names(self, name_prefix):
def prepare_field_objs_and_params(self, manipulator, name_prefix):
params = {'validator_list': self.validator_list[:]}
- if self.maxlength and not self.choices: # Don't give SelectFields a maxlength parameter.
- params['maxlength'] = self.maxlength
+ if self.max_length and not self.choices: # Don't give SelectFields a max_length parameter.
+ params['max_length'] = self.max_length
if self.choices:
if self.radio_admin:
@@ -461,7 +465,7 @@ def to_python(self, value):
return smart_unicode(value)
def formfield(self, **kwargs):
- defaults = {'max_length': self.maxlength}
+ defaults = {'max_length': self.max_length}
defaults.update(kwargs)
return super(CharField, self).formfield(**defaults)
@@ -670,7 +674,7 @@ def formfield(self, **kwargs):
class EmailField(CharField):
def __init__(self, *args, **kwargs):
- kwargs['maxlength'] = 75
+ kwargs['max_length'] = 75
CharField.__init__(self, *args, **kwargs)
def get_internal_type(self):
@@ -829,7 +833,7 @@ def formfield(self, **kwargs):
class IPAddressField(Field):
empty_strings_allowed = False
def __init__(self, *args, **kwargs):
- kwargs['maxlength'] = 15
+ kwargs['max_length'] = 15
Field.__init__(self, *args, **kwargs)
def get_manipulator_field_objs(self):
@@ -877,7 +881,7 @@ def get_manipulator_field_objs(self):
class SlugField(Field):
def __init__(self, *args, **kwargs):
- kwargs['maxlength'] = kwargs.get('maxlength', 50)
+ kwargs['max_length'] = kwargs.get('max_length', 50)
kwargs.setdefault('validator_list', []).append(validators.isSlug)
# Set db_index=True unless it's been set manually.
if 'db_index' not in kwargs:
@@ -963,7 +967,7 @@ def formfield(self, **kwargs):
class URLField(CharField):
def __init__(self, verbose_name=None, name=None, verify_exists=True, **kwargs):
- kwargs['maxlength'] = kwargs.get('maxlength', 200)
+ kwargs['max_length'] = kwargs.get('max_length', 200)
if verify_exists:
kwargs.setdefault('validator_list', []).append(validators.isExistingURL)
self.verify_exists = verify_exists
View
1  django/newforms/fields.py
@@ -120,6 +120,7 @@ def clean(self, value):
def widget_attrs(self, widget):
if self.max_length is not None and isinstance(widget, (TextInput, PasswordInput)):
+ # The HTML attribute is maxlength, not max_length.
return {'maxlength': str(self.max_length)}
class IntegerField(Field):
View
116 django/oldforms/__init__.py
@@ -4,6 +4,7 @@
from django.conf import settings
from django.utils.translation import ugettext, ungettext
from django.utils.encoding import smart_unicode, force_unicode
+from django.utils.maxlength import LegacyMaxlength
FORM_FIELD_ID_PREFIX = 'id_'
@@ -302,6 +303,9 @@ class FormField(object):
Subclasses should also implement a render(data) method, which is responsible
for rending the form field in XHTML.
"""
+ # Provide backwards compatibility for the maxlength attribute and
+ # argument for this class and all subclasses.
+ __metaclass__ = LegacyMaxlength
def __str__(self):
return unicode(self).encode('utf-8')
@@ -390,19 +394,19 @@ def get_id(self):
class TextField(FormField):
input_type = "text"
- def __init__(self, field_name, length=30, maxlength=None, is_required=False, validator_list=None, member_name=None):
+ def __init__(self, field_name, length=30, max_length=None, is_required=False, validator_list=None, member_name=None):
if validator_list is None: validator_list = []
self.field_name = field_name
- self.length, self.maxlength = length, maxlength
+ self.length, self.max_length = length, max_length
self.is_required = is_required
self.validator_list = [self.isValidLength, self.hasNoNewlines] + validator_list
if member_name != None:
self.member_name = member_name
def isValidLength(self, data, form):
- if data and self.maxlength and len(smart_unicode(data)) > self.maxlength:
+ if data and self.max_length and len(smart_unicode(data)) > self.max_length:
raise validators.ValidationError, ungettext("Ensure your text is less than %s character.",
- "Ensure your text is less than %s characters.", self.maxlength) % self.maxlength
+ "Ensure your text is less than %s characters.", self.max_length) % self.max_length
def hasNoNewlines(self, data, form):
if data and '\n' in data:
@@ -411,12 +415,12 @@ def hasNoNewlines(self, data, form):
def render(self, data):
if data is None:
data = u''
- maxlength = u''
- if self.maxlength:
- maxlength = u'maxlength="%s" ' % self.maxlength
+ max_length = u''
+ if self.max_length:
+ max_length = u'maxlength="%s" ' % self.max_length
return u'<input type="%s" id="%s" class="v%s%s" name="%s" size="%s" value="%s" %s/>' % \
(self.input_type, self.get_id(), self.__class__.__name__, self.is_required and u' required' or '',
- self.field_name, self.length, escape(data), maxlength)
+ self.field_name, self.length, escape(data), max_length)
def html2python(data):
return data
@@ -426,14 +430,14 @@ class PasswordField(TextField):
input_type = "password"
class LargeTextField(TextField):
- def __init__(self, field_name, rows=10, cols=40, is_required=False, validator_list=None, maxlength=None):
+ def __init__(self, field_name, rows=10, cols=40, is_required=False, validator_list=None, max_length=None):
if validator_list is None: validator_list = []
self.field_name = field_name
self.rows, self.cols, self.is_required = rows, cols, is_required
self.validator_list = validator_list[:]
- if maxlength:
+ if max_length:
self.validator_list.append(self.isValidLength)
- self.maxlength = maxlength
+ self.max_length = max_length
def render(self, data):
if data is None:
@@ -710,12 +714,12 @@ def isValidImage(self, field_data, all_data):
####################
class IntegerField(TextField):
- def __init__(self, field_name, length=10, maxlength=None, is_required=False, validator_list=None, member_name=None):
+ def __init__(self, field_name, length=10, max_length=None, is_required=False, validator_list=None, member_name=None):
if validator_list is None: validator_list = []
validator_list = [self.isInteger] + validator_list
if member_name is not None:
self.member_name = member_name
- TextField.__init__(self, field_name, length, maxlength, is_required, validator_list)
+ TextField.__init__(self, field_name, length, max_length, is_required, validator_list)
def isInteger(self, field_data, all_data):
try:
@@ -730,57 +734,57 @@ def html2python(data):
html2python = staticmethod(html2python)
class SmallIntegerField(IntegerField):
- def __init__(self, field_name, length=5, maxlength=5, is_required=False, validator_list=None):
+ def __init__(self, field_name, length=5, max_length=5, is_required=False, validator_list=None):
if validator_list is None: validator_list = []
validator_list = [self.isSmallInteger] + validator_list
- IntegerField.__init__(self, field_name, length, maxlength, is_required, validator_list)
+ IntegerField.__init__(self, field_name, length, max_length, is_required, validator_list)
def isSmallInteger(self, field_data, all_data):
if not -32768 <= int(field_data) <= 32767:
raise validators.CriticalValidationError, ugettext("Enter a whole number between -32,768 and 32,767.")
class PositiveIntegerField(IntegerField):
- def __init__(self, field_name, length=10, maxlength=None, is_required=False, validator_list=None):
+ def __init__(self, field_name, length=10, max_length=None, is_required=False, validator_list=None):
if validator_list is None: validator_list = []
validator_list = [self.isPositive] + validator_list
- IntegerField.__init__(self, field_name, length, maxlength, is_required, validator_list)
+ IntegerField.__init__(self, field_name, length, max_length, is_required, validator_list)
def isPositive(self, field_data, all_data):
if int(field_data) < 0:
raise validators.CriticalValidationError, ugettext("Enter a positive number.")
class PositiveSmallIntegerField(IntegerField):
- def __init__(self, field_name, length=5, maxlength=None, is_required=False, validator_list=None):
+ def __init__(self, field_name, length=5, max_length=None, is_required=False, validator_list=None):
if validator_list is None: validator_list = []
validator_list = [self.isPositiveSmall] + validator_list
- IntegerField.__init__(self, field_name, length, maxlength, is_required, validator_list)
+ IntegerField.__init__(self, field_name, length, max_length, is_required, validator_list)
def isPositiveSmall(self, field_data, all_data):
if not 0 <= int(field_data) <= 32767:
raise validators.CriticalValidationError, ugettext("Enter a whole number between 0 and 32,767.")
class FloatField(TextField):
- def __init__(self, field_name, is_required=False, validator_list=None):
- if validator_list is None: validator_list = []
- validator_list = [validators.isValidFloat] + validator_list
- TextField.__init__(self, field_name, is_required=is_required, validator_list=validator_list)
-
- def html2python(data):
- if data == '' or data is None:
- return None
- return float(data)
- html2python = staticmethod(html2python)
-
-class DecimalField(TextField):
+ def __init__(self, field_name, is_required=False, validator_list=None):
+ if validator_list is None: validator_list = []
+ validator_list = [validators.isValidFloat] + validator_list
+ TextField.__init__(self, field_name, is_required=is_required, validator_list=validator_list)
+
+ def html2python(data):
+ if data == '' or data is None:
+ return None
+ return float(data)
+ html2python = staticmethod(html2python)
+
+class DecimalField(TextField):
def __init__(self, field_name, max_digits, decimal_places, is_required=False, validator_list=None):
if validator_list is None: validator_list = []
self.max_digits, self.decimal_places = max_digits, decimal_places
- validator_list = [self.isValidDecimal] + validator_list
- # Initialise the TextField, making sure it's large enough to fit the number with a - sign and a decimal point.
- super(DecimalField, self).__init__(field_name, max_digits+2, max_digits+2, is_required, validator_list)
+ validator_list = [self.isValidDecimal] + validator_list
+ # Initialise the TextField, making sure it's large enough to fit the number with a - sign and a decimal point.
+ super(DecimalField, self).__init__(field_name, max_digits+2, max_digits+2, is_required, validator_list)
- def isValidDecimal(self, field_data, all_data):
- v = validators.IsValidDecimal(self.max_digits, self.decimal_places)
+ def isValidDecimal(self, field_data, all_data):
+ v = validators.IsValidDecimal(self.max_digits, self.decimal_places)
try:
v(field_data, all_data)
except validators.ValidationError, e:
@@ -789,14 +793,14 @@ def isValidDecimal(self, field_data, all_data):
def html2python(data):
if data == '' or data is None:
return None
- try:
- import decimal
+ try:
+ import decimal
except ImportError:
from django.utils import _decimal as decimal
- try:
- return decimal.Decimal(data)
- except decimal.InvalidOperation, e:
- raise ValueError, e
+ try:
+ return decimal.Decimal(data)
+ except decimal.InvalidOperation, e:
+ raise ValueError, e
html2python = staticmethod(html2python)
####################
@@ -806,10 +810,10 @@ def html2python(data):
class DatetimeField(TextField):
"""A FormField that automatically converts its data to a datetime.datetime object.
The data should be in the format YYYY-MM-DD HH:MM:SS."""
- def __init__(self, field_name, length=30, maxlength=None, is_required=False, validator_list=None):
+ def __init__(self, field_name, length=30, max_length=None, is_required=False, validator_list=None):
if validator_list is None: validator_list = []
self.field_name = field_name
- self.length, self.maxlength = length, maxlength
+ self.length, self.max_length = length, max_length
self.is_required = is_required
self.validator_list = [validators.isValidANSIDatetime] + validator_list
@@ -836,7 +840,7 @@ class DateField(TextField):
def __init__(self, field_name, is_required=False, validator_list=None):
if validator_list is None: validator_list = []
validator_list = [self.isValidDate] + validator_list
- TextField.__init__(self, field_name, length=10, maxlength=10,
+ TextField.__init__(self, field_name, length=10, max_length=10,
is_required=is_required, validator_list=validator_list)
def isValidDate(self, field_data, all_data):
@@ -861,7 +865,7 @@ class TimeField(TextField):
def __init__(self, field_name, is_required=False, validator_list=None):
if validator_list is None: validator_list = []
validator_list = [self.isValidTime] + validator_list
- TextField.__init__(self, field_name, length=8, maxlength=8,
+ TextField.__init__(self, field_name, length=8, max_length=8,
is_required=is_required, validator_list=validator_list)
def isValidTime(self, field_data, all_data):
@@ -893,10 +897,10 @@ def html2python(data):
class EmailField(TextField):
"A convenience FormField for validating e-mail addresses"
- def __init__(self, field_name, length=50, maxlength=75, is_required=False, validator_list=None):
+ def __init__(self, field_name, length=50, max_length=75, is_required=False, validator_list=None):
if validator_list is None: validator_list = []
validator_list = [self.isValidEmail] + validator_list
- TextField.__init__(self, field_name, length, maxlength=maxlength,
+ TextField.__init__(self, field_name, length, max_length=max_length,
is_required=is_required, validator_list=validator_list)
def isValidEmail(self, field_data, all_data):
@@ -907,10 +911,10 @@ def isValidEmail(self, field_data, all_data):
class URLField(TextField):
"A convenience FormField for validating URLs"
- def __init__(self, field_name, length=50, maxlength=200, is_required=False, validator_list=None):
+ def __init__(self, field_name, length=50, max_length=200, is_required=False, validator_list=None):
if validator_list is None: validator_list = []
validator_list = [self.isValidURL] + validator_list
- TextField.__init__(self, field_name, length=length, maxlength=maxlength,
+ TextField.__init__(self, field_name, length=length, max_length=max_length,
is_required=is_required, validator_list=validator_list)
def isValidURL(self, field_data, all_data):
@@ -920,10 +924,10 @@ def isValidURL(self, field_data, all_data):
raise validators.CriticalValidationError, e.messages
class IPAddressField(TextField):
- def __init__(self, field_name, length=15, maxlength=15, is_required=False, validator_list=None):
+ def __init__(self, field_name, length=15, max_length=15, is_required=False, validator_list=None):
if validator_list is None: validator_list = []
validator_list = [self.isValidIPAddress] + validator_list
- TextField.__init__(self, field_name, length=length, maxlength=maxlength,
+ TextField.__init__(self, field_name, length=length, max_length=max_length,
is_required=is_required, validator_list=validator_list)
def isValidIPAddress(self, field_data, all_data):
@@ -970,7 +974,7 @@ class PhoneNumberField(TextField):
def __init__(self, field_name, is_required=False, validator_list=None):
if validator_list is None: validator_list = []
validator_list = [self.isValidPhone] + validator_list
- TextField.__init__(self, field_name, length=12, maxlength=12,
+ TextField.__init__(self, field_name, length=12, max_length=12,
is_required=is_required, validator_list=validator_list)
def isValidPhone(self, field_data, all_data):
@@ -984,7 +988,7 @@ class USStateField(TextField):
def __init__(self, field_name, is_required=False, validator_list=None):
if validator_list is None: validator_list = []
validator_list = [self.isValidUSState] + validator_list
- TextField.__init__(self, field_name, length=2, maxlength=2,
+ TextField.__init__(self, field_name, length=2, max_length=2,
is_required=is_required, validator_list=validator_list)
def isValidUSState(self, field_data, all_data):
@@ -1001,10 +1005,10 @@ def html2python(data):
class CommaSeparatedIntegerField(TextField):
"A convenience FormField for validating comma-separated integer fields"
- def __init__(self, field_name, maxlength=None, is_required=False, validator_list=None):
+ def __init__(self, field_name, max_length=None, is_required=False, validator_list=None):
if validator_list is None: validator_list = []
validator_list = [self.isCommaSeparatedIntegerList] + validator_list
- TextField.__init__(self, field_name, length=20, maxlength=maxlength,
+ TextField.__init__(self, field_name, length=20, max_length=max_length,
is_required=is_required, validator_list=validator_list)
def isCommaSeparatedIntegerList(self, field_data, all_data):
View
67 django/utils/maxlength.py
@@ -0,0 +1,67 @@
+"""
+Utilities for providing backwards compatibility for the maxlength argument,
+which has been replaced by max_length, see ticket #2101.
+"""
+
+from warnings import warn
+
+def get_maxlength(self):
+ return self.max_length
+
+def set_maxlength(self, value):
+ self.max_length = value
+
+def legacy_maxlength(max_length, maxlength):
+ """
+ Consolidates max_length and maxlength, providing backwards compatibilty
+ for the legacy "maxlength" argument.
+ If one of max_length or maxlength is given, then that value is returned.
+ If both are given, a TypeError is raised.
+ If maxlength is used at all, a deprecation warning is issued.
+ """
+ if maxlength is not None:
+ warn("maxlength is deprecated, use max_length instead.",
+ PendingDeprecationWarning,
+ stacklevel=3)
+ if max_length is not None:
+ raise TypeError("field can not take both the max_length"
+ " argument and the legacy maxlength argument.")
+ max_length = maxlength
+ return max_length
+
+def remove_maxlength(func):
+ """
+ A decorator to be used on a class's __init__ that provides backwards
+ compatibilty for the legacy "maxlength" keyword argument, i.e.
+ name = models.CharField(maxlength=20)
+ It does this by changing the passed "maxlength" keyword argument
+ (if it exists) into a "max_length" keyword argument.
+ """
+ def inner(self, *args, **kwargs):
+ max_length = kwargs.get('max_length', None)
+ # pop maxlength because we don't want this going to __init__.
+ maxlength = kwargs.pop('maxlength', None)
+ max_length = legacy_maxlength(max_length, maxlength)
+ # Only set the max_length keyword argument if we got a value back.
+ if max_length is not None:
+ kwargs['max_length'] = max_length
+ func(self, *args, **kwargs)
+ return inner
+
+# This metaclass is used in two places, and should be removed when legacy
+# support for maxlength is dropped.
+# * oldforms.FormField
+# * db.models.fields.Field
+
+class LegacyMaxlength(type):
+ """
+ Metaclass for providing backwards compatibility support for the
+ "maxlength" keyword argument.
+ """
+
+ def __init__(cls, name, bases, attrs):
+ super(LegacyMaxlength, cls).__init__(name, bases, attrs)
+ # Decorate the class's __init__ to remove any maxlength keyword.
+ cls.__init__ = remove_maxlength(cls.__init__)
+ # Support accessing and setting to the legacy maxlength attribute.
+ cls.maxlength = property(get_maxlength, set_maxlength)
View
20 docs/contributing.txt
@@ -340,14 +340,14 @@ Model style
Do this::
class Person(models.Model):
- first_name = models.CharField(maxlength=20)
- last_name = models.CharField(maxlength=40)
+ first_name = models.CharField(max_length=20)
+ last_name = models.CharField(max_length=40)
Don't do this::
class Person(models.Model):
- FirstName = models.CharField(maxlength=20)
- Last_Name = models.CharField(maxlength=40)
+ FirstName = models.CharField(max_length=20)
+ Last_Name = models.CharField(max_length=40)
* The ``class Meta`` should appear *after* the fields are defined, with
a single blank line separating the fields and the class definition.
@@ -355,8 +355,8 @@ Model style
Do this::
class Person(models.Model):
- first_name = models.CharField(maxlength=20)
- last_name = models.CharField(maxlength=40)
+ first_name = models.CharField(max_length=20)
+ last_name = models.CharField(max_length=40)
class Meta:
verbose_name_plural = 'people'
@@ -364,8 +364,8 @@ Model style
Don't do this::
class Person(models.Model):
- first_name = models.CharField(maxlength=20)
- last_name = models.CharField(maxlength=40)
+ first_name = models.CharField(max_length=20)
+ last_name = models.CharField(max_length=40)
class Meta:
verbose_name_plural = 'people'
@@ -375,8 +375,8 @@ Model style
class Meta:
verbose_name_plural = 'people'
- first_name = models.CharField(maxlength=20)
- last_name = models.CharField(maxlength=40)
+ first_name = models.CharField(max_length=20)
+ last_name = models.CharField(max_length=40)
* The order of model inner classes and standard methods should be as
follows (noting that these are not all required):
View
10 docs/db-api.txt
@@ -12,14 +12,14 @@ Throughout this reference, we'll refer to the following models, which comprise
a weblog application::
class Blog(models.Model):
- name = models.CharField(maxlength=100)
+ name = models.CharField(max_length=100)
tagline = models.TextField()
def __unicode__(self):
return self.name
class Author(models.Model):
- name = models.CharField(maxlength=50)
+ name = models.CharField(max_length=50)
email = models.EmailField()
def __unicode__(self):
@@ -27,7 +27,7 @@ a weblog application::
class Entry(models.Model):
blog = models.ForeignKey(Blog)
- headline = models.CharField(maxlength=255)
+ headline = models.CharField(max_length=255)
body_text = models.TextField()
pub_date = models.DateTimeField()
authors = models.ManyToManyField(Author)
@@ -1806,8 +1806,8 @@ following model::
('F', 'Female'),
)
class Person(models.Model):
- name = models.CharField(maxlength=20)
- gender = models.CharField(maxlength=1, choices=GENDER_CHOICES)
+ name = models.CharField(max_length=20)
+ gender = models.CharField(max_length=1, choices=GENDER_CHOICES)
...each ``Person`` instance will have a ``get_gender_display()`` method. Example::
View
10 docs/forms.txt
@@ -37,11 +37,11 @@ this document, we'll be working with the following model, a "place" object::
)
class Place(models.Model):
- name = models.CharField(maxlength=100)
- address = models.CharField(maxlength=100, blank=True)
- city = models.CharField(maxlength=50, blank=True)
+ name = models.CharField(max_length=100)
+ address = models.CharField(max_length=100, blank=True)
+ city = models.CharField(max_length=50, blank=True)
state = models.USStateField()
- zip_code = models.CharField(maxlength=5, blank=True)
+ zip_code = models.CharField(max_length=5, blank=True)
place_type = models.IntegerField(choices=PLACE_TYPES)
class Admin:
@@ -388,7 +388,7 @@ for a "contact" form on a website::
def __init__(self):
self.fields = (
forms.EmailField(field_name="from", is_required=True),
- forms.TextField(field_name="subject", length=30, maxlength=200, is_required=True),
+ forms.TextField(field_name="subject", length=30, max_length=200, is_required=True),
forms.SelectField(field_name="urgency", choices=urgency_choices),
forms.LargeTextField(field_name="contents", is_required=True),
)
View
110 docs/model-api.txt
@@ -33,8 +33,8 @@ This example model defines a ``Person``, which has a ``first_name`` and
from django.db import models
class Person(models.Model):
- first_name = models.CharField(maxlength=30)
- last_name = models.CharField(maxlength=30)
+ first_name = models.CharField(max_length=30)
+ last_name = models.CharField(max_length=30)
``first_name`` and ``last_name`` are *fields* of the model. Each field is
specified as a class attribute, and each attribute maps to a database column.
@@ -69,13 +69,13 @@ attributes.
Example::
class Musician(models.Model):
- first_name = models.CharField(maxlength=50)
- last_name = models.CharField(maxlength=50)
- instrument = models.CharField(maxlength=100)
+ first_name = models.CharField(max_length=50)
+ last_name = models.CharField(max_length=50)
+ instrument = models.CharField(max_length=100)
class Album(models.Model):
artist = models.ForeignKey(Musician)
- name = models.CharField(maxlength=100)
+ name = models.CharField(max_length=100)
release_date = models.DateField()
num_stars = models.IntegerField()
@@ -142,14 +142,18 @@ For large amounts of text, use ``TextField``.
The admin represents this as an ``<input type="text">`` (a single-line input).
-``CharField`` has an extra required argument, ``maxlength``, the maximum length
-(in characters) of the field. The maxlength is enforced at the database level
+``CharField`` has an extra required argument, ``max_length``, the maximum length
+(in characters) of the field. The max_length is enforced at the database level
and in Django's validation.
-``CommaSeparatedIntegerField``
+Django veterans: Note that the argument is now called ``max_length`` to
+provide consistency throughout Django. There is full legacy support for
+the old ``maxlength`` argument, but ``max_length`` is prefered.
+
+ ``CommaSeparatedIntegerField``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-A field of integers separated by commas. As in ``CharField``, the ``maxlength``
+A field of integers separated by commas. As in ``CharField``, the ``max_length``
argument is required.
``DateField``
@@ -217,7 +221,7 @@ The admin represents this as an ``<input type="text">`` (a single-line input).
~~~~~~~~~~~~~~
A ``CharField`` that checks that the value is a valid e-mail address.
-This doesn't accept ``maxlength``; its ``maxlength`` is automatically set to
+This doesn't accept ``max_length``; its ``max_length`` is automatically set to
75.
``FileField``
@@ -400,7 +404,7 @@ Like a ``PositiveIntegerField``, but only allows values under a certain
containing only letters, numbers, underscores or hyphens. They're generally
used in URLs.
-Like a CharField, you can specify ``maxlength``. If ``maxlength`` is
+Like a CharField, you can specify ``max_length``. If ``max_length`` is
not specified, Django will use a default length of 50.
Implies ``db_index=True``.
@@ -447,9 +451,9 @@ and doesn't give a 404 response).
The admin represents this as an ``<input type="text">`` (a single-line input).
-``URLField`` takes an optional argument, ``maxlength``, the maximum length (in
-characters) of the field. The maxlength is enforced at the database level and
-in Django's validation. If you don't specify ``maxlength``, a default of 200
+``URLField`` takes an optional argument, ``max_length``, the maximum length (in
+characters) of the field. The maximum length is enforced at the database level and
+in Django's validation. If you don't specify ``max_length``, a default of 200
is used.
``USStateField``
@@ -536,7 +540,7 @@ The choices list can be defined either as part of your model class::
('M', 'Male'),
('F', 'Female'),
)
- gender = models.CharField(maxlength=1, choices=GENDER_CHOICES)
+ gender = models.CharField(max_length=1, choices=GENDER_CHOICES)
or outside your model class altogether::
@@ -545,7 +549,7 @@ or outside your model class altogether::
('F', 'Female'),
)
class Foo(models.Model):
- gender = models.CharField(maxlength=1, choices=GENDER_CHOICES)
+ gender = models.CharField(max_length=1, choices=GENDER_CHOICES)
For each model field that has ``choices`` set, Django will add a method to
retrieve the human-readable name for the field's current value. See
@@ -698,11 +702,11 @@ it using the field's attribute name, converting underscores to spaces.
In this example, the verbose name is ``"Person's first name"``::
- first_name = models.CharField("Person's first name", maxlength=30)
+ first_name = models.CharField("Person's first name", max_length=30)
In this example, the verbose name is ``"first name"``::
- first_name = models.CharField(maxlength=30)
+ first_name = models.CharField(max_length=30)
``ForeignKey``, ``ManyToManyField`` and ``OneToOneField`` require the first
argument to be a model class, so use the ``verbose_name`` keyword argument::
@@ -1027,8 +1031,8 @@ Once you have ``MytypeField``, you can use it in any model, just like any other
``Field`` type::
class Person(models.Model):
- name = models.CharField(maxlength=80)
- gender = models.CharField(maxlength=1)
+ name = models.CharField(max_length=80)
+ gender = models.CharField(max_length=1)
something_else = MytypeField()
If you aim to build a database-agnostic application, you should account for
@@ -1074,12 +1078,12 @@ time -- i.e., when the class is instantiated. To do that, just implement
# This is a much more flexible example.
class BetterCharField(models.Field):
- def __init__(self, maxlength, *args, **kwargs):
- self.maxlength = maxlength
+ def __init__(self, max_length, *args, **kwargs):
+ self.max_length = max_length
super(BetterCharField, self).__init__(*args, **kwargs)
def db_type(self):
- return 'char(%s)' % self.maxlength
+ return 'char(%s)' % self.max_length
# In the model:
class MyModel(models.Model):
@@ -1096,7 +1100,7 @@ Meta options
Give your model metadata by using an inner ``class Meta``, like so::
class Foo(models.Model):
- bar = models.CharField(maxlength=30)
+ bar = models.CharField(max_length=30)
class Meta:
# ...
@@ -1270,8 +1274,8 @@ If you want your model to be visible to Django's admin site, give your model an
inner ``"class Admin"``, like so::
class Person(models.Model):
- first_name = models.CharField(maxlength=30)
- last_name = models.CharField(maxlength=30)
+ first_name = models.CharField(max_length=30)
+ last_name = models.CharField(max_length=30)
class Admin:
# Admin options go here
@@ -1430,7 +1434,7 @@ A few special cases to note about ``list_display``:
Here's a full example model::
class Person(models.Model):
- name = models.CharField(maxlength=50)
+ name = models.CharField(max_length=50)
birthday = models.DateField()
class Admin:
@@ -1447,9 +1451,9 @@ A few special cases to note about ``list_display``:
Here's a full example model::
class Person(models.Model):
- first_name = models.CharField(maxlength=50)
- last_name = models.CharField(maxlength=50)
- color_code = models.CharField(maxlength=6)
+ first_name = models.CharField(max_length=50)
+ last_name = models.CharField(max_length=50)
+ color_code = models.CharField(max_length=6)
class Admin:
list_display = ('first_name', 'last_name', 'colored_name')
@@ -1465,7 +1469,7 @@ A few special cases to note about ``list_display``:
Here's a full example model::
class Person(models.Model):
- first_name = models.CharField(maxlength=50)
+ first_name = models.CharField(max_length=50)
birthday = models.DateField()
class Admin:
@@ -1493,8 +1497,8 @@ A few special cases to note about ``list_display``:
For example::
class Person(models.Model):
- first_name = models.CharField(maxlength=50)
- color_code = models.CharField(maxlength=6)
+ first_name = models.CharField(max_length=50)
+ color_code = models.CharField(max_length=6)
class Admin:
list_display = ('first_name', 'colored_first_name')
@@ -1744,13 +1748,13 @@ returns a list of all ``OpinionPoll`` objects, each with an extra
return result_list
class OpinionPoll(models.Model):
- question = models.CharField(maxlength=200)
+ question = models.CharField(max_length=200)
poll_date = models.DateField()
objects = PollManager()
class Response(models.Model):
poll = models.ForeignKey(Poll)
- person_name = models.CharField(maxlength=50)
+ person_name = models.CharField(max_length=50)
response = models.TextField()
With this example, you'd use ``OpinionPoll.objects.with_counts()`` to return
@@ -1766,8 +1770,8 @@ A ``Manager``'s base ``QuerySet`` returns all objects in the system. For
example, using this model::
class Book(models.Model):
- title = models.CharField(maxlength=100)
- author = models.CharField(maxlength=50)
+ title = models.CharField(max_length=100)
+ author = models.CharField(max_length=50)
...the statement ``Book.objects.all()`` will return all books in the database.
@@ -1785,8 +1789,8 @@ all objects, and one that returns only the books by Roald Dahl::
# Then hook it into the Book model explicitly.
class Book(models.Model):
- title = models.CharField(maxlength=100)
- author = models.CharField(maxlength=50)
+ title = models.CharField(max_length=100)
+ author = models.CharField(max_length=50)
objects = models.Manager() # The default manager.
dahl_objects = DahlBookManager() # The Dahl-specific manager.
@@ -1819,9 +1823,9 @@ For example::
return super(FemaleManager, self).get_query_set().filter(sex='F')
class Person(models.Model):
- first_name = models.CharField(maxlength=50)
- last_name = models.CharField(maxlength=50)
- sex = models.CharField(maxlength=1, choices=(('M', 'Male'), ('F', 'Female')))
+ first_name = models.CharField(max_length=50)
+ last_name = models.CharField(max_length=50)
+ sex = models.CharField(max_length=1, choices=(('M', 'Male'), ('F', 'Female')))
people = models.Manager()
men = MaleManager()
women = FemaleManager()
@@ -1851,11 +1855,11 @@ model.
For example, this model has a few custom methods::
class Person(models.Model):
- first_name = models.CharField(maxlength=50)
- last_name = models.CharField(maxlength=50)
+ first_name = models.CharField(max_length=50)
+ last_name = models.CharField(max_length=50)
birth_date = models.DateField()
- address = models.CharField(maxlength=100)
- city = models.CharField(maxlength=50)
+ address = models.CharField(max_length=100)
+ city = models.CharField(max_length=50)
state = models.USStateField() # Yes, this is America-centric...
def baby_boomer_status(self):
@@ -1897,8 +1901,8 @@ Although this isn't required, it's strongly encouraged (see the description of
For example::
class Person(models.Model):
- first_name = models.CharField(maxlength=50)
- last_name = models.CharField(maxlength=50)
+ first_name = models.CharField(max_length=50)
+ last_name = models.CharField(max_length=50)
def __str__(self):
# Note use of django.utils.encoding.smart_str() here because
@@ -1915,8 +1919,8 @@ method for your model. The example in the previous section could be written
more simply as::
class Person(models.Model):
- first_name = models.CharField(maxlength=50)
- last_name = models.CharField(maxlength=50)
+ first_name = models.CharField(max_length=50)
+ last_name = models.CharField(max_length=50)
def __unicode__(self):
return u'%s %s' % (self.first_name, self.last_name)
@@ -2058,7 +2062,7 @@ A classic use-case for overriding the built-in methods is if you want something
to happen whenever you save an object. For example::
class Blog(models.Model):
- name = models.CharField(maxlength=100)
+ name = models.CharField(max_length=100)
tagline = models.TextField()
def save(self):
@@ -2069,7 +2073,7 @@ to happen whenever you save an object. For example::
You can also prevent saving::
class Blog(models.Model):
- name = models.CharField(maxlength=100)
+ name = models.CharField(max_length=100)
tagline = models.TextField()
def save(self):
View
8 docs/newforms.txt
@@ -1372,7 +1372,7 @@ the full list of conversions:
``AutoField`` Not represented in the form
``BooleanField`` ``BooleanField``
``CharField`` ``CharField`` with ``max_length`` set to
- the model field's ``maxlength``
+ the model field's ``max_length``
``CommaSeparatedIntegerField`` ``CharField``
``DateField`` ``DateField``
``DateTimeField`` ``DateTimeField``
@@ -1452,15 +1452,15 @@ Consider this set of models::
)
class Author(models.Model):
- name = models.CharField(maxlength=100)
- title = models.CharField(maxlength=3, choices=TITLE_CHOICES)
+ name = models.CharField(max_length=100)
+ title = models.CharField(max_length=3, choices=TITLE_CHOICES)
birth_date = models.DateField(blank=True, null=True)
def __unicode__(self):
return self.name
class Book(models.Model):
- name = models.CharField(maxlength=100)
+ name = models.CharField(max_length=100)
authors = models.ManyToManyField(Author)
With these models, a call to ``form_for_model(Author)`` would return a ``Form``
View
6 docs/overview.txt
@@ -25,14 +25,14 @@ far, it's been solving two years' worth of database-schema problems. Here's a
quick example::
class Reporter(models.Model):
- full_name = models.CharField(maxlength=70)
+ full_name = models.CharField(max_length=70)
def __unicode__(self):
return self.full_name
class Article(models.Model):
pub_date = models.DateTimeField()
- headline = models.CharField(maxlength=200)
+ headline = models.CharField(max_length=200)
article = models.TextField()
reporter = models.ForeignKey(Reporter)
@@ -134,7 +134,7 @@ your model classes::
class Article(models.Model):
pub_date = models.DateTimeField()
- headline = models.CharField(maxlength=200)
+ headline = models.CharField(max_length=200)
article = models.TextField()
reporter = models.ForeignKey(Reporter)
class Admin: pass
View
8 docs/sites.txt
@@ -46,7 +46,7 @@ that's represented by a ``ManyToManyField`` in the ``Article`` model::
from django.contrib.sites.models import Site
class Article(models.Model):
- headline = models.CharField(maxlength=200)
+ headline = models.CharField(max_length=200)
# ...
sites = models.ManyToManyField(Site)
@@ -87,7 +87,7 @@ like this::
from django.contrib.sites.models import Site
class Article(models.Model):
- headline = models.CharField(maxlength=200)
+ headline = models.CharField(max_length=200)
# ...
site = models.ForeignKey(Site)
@@ -229,7 +229,7 @@ Use ``CurrentSiteManager`` by adding it to your model explicitly. For example::
class Photo(models.Model):
photo = models.FileField(upload_to='/home/photos')
- photographer_name = models.CharField(maxlength=100)
+ photographer_name = models.CharField(max_length=100)
pub_date = models.DateField()
site = models.ForeignKey(Site)
objects = models.Manager()
@@ -257,7 +257,7 @@ this::
class Photo(models.Model):
photo = models.FileField(upload_to='/home/photos')
- photographer_name = models.CharField(maxlength=100)
+ photographer_name = models.CharField(max_length=100)
pub_date = models.DateField()
publish_on = models.ForeignKey(Site)
objects = models.Manager()
View
4 docs/testing.txt
@@ -79,8 +79,8 @@ For example::
'The cat says "meow"'
"""
- name = models.CharField(maxlength=20)
- sound = models.CharField(maxlength=20)
+ name = models.CharField(max_length=20)
+ sound = models.CharField(max_length=20)
def speak(self):
return 'The %s says "%s"' % (self.name, self.sound)
View
6 docs/tutorial01.txt
@@ -251,12 +251,12 @@ These concepts are represented by simple Python classes. Edit the
from django.db import models
class Poll(models.Model):
- question = models.CharField(maxlength=200)
+ question = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
class Choice(models.Model):
poll = models.ForeignKey(Poll)
- choice = models.CharField(maxlength=200)
+ choice = models.CharField(max_length=200)
votes = models.IntegerField()
The code is straightforward. Each model is represented by a class that
@@ -279,7 +279,7 @@ name for ``Poll.pub_date``. For all other fields in this model, the field's
machine-readable name will suffice as its human-readable name.
Some ``Field`` classes have required elements. ``CharField``, for example,
-requires that you give it a ``maxlength``. That's used not only in the database
+requires that you give it a ``max_length``. That's used not only in the database
schema, but in validation, as we'll soon see.
Finally, note a relationship is defined, using ``models.ForeignKey``. That tells
View
2  docs/tutorial02.txt
@@ -240,7 +240,7 @@ default, provide enough fields for 3 Choices."
Then change the other fields in ``Choice`` to give them ``core=True``::
- choice = models.CharField(maxlength=200, core=True)
+ choice = models.CharField(max_length=200, core=True)
votes = models.IntegerField(core=True)
This tells Django: "When you edit a Choice on the Poll admin page, the 'choice'
View
2  tests/modeltests/basic/models.py
@@ -8,7 +8,7 @@
from django.db import models
class Article(models.Model):
- headline = models.CharField(maxlength=100, default='Default headline')
+ headline = models.CharField(max_length=100, default='Default headline')
pub_date = models.DateTimeField()
class Meta:
View
4 tests/modeltests/choices/models.py
@@ -17,8 +17,8 @@
)
class Person(models.Model):
- name = models.CharField(maxlength=20)
- gender = models.CharField(maxlength=1, choices=GENDER_CHOICES)
+ name = models.CharField(max_length=20)
+ gender = models.CharField(max_length=1, choices=GENDER_CHOICES)
def __unicode__(self):
return self.name
View
6 tests/modeltests/custom_columns/models.py
@@ -18,8 +18,8 @@
from django.db import models
class Author(models.Model):
- first_name = models.CharField(maxlength=30, db_column='firstname')
- last_name = models.CharField(maxlength=30, db_column='last')
+ first_name = models.CharField(max_length=30, db_column='firstname')
+ last_name = models.CharField(max_length=30, db_column='last')
def __unicode__(self):
return u'%s %s' % (self.first_name, self.last_name)
@@ -29,7 +29,7 @@ class Meta:
ordering = ('last_name','first_name')
class Article(models.Model):
- headline = models.CharField(maxlength=100)
+ headline = models.CharField(max_length=100)
authors = models.ManyToManyField(Author, db_table='my_m2m_table')
def __unicode__(self):
View
10 tests/modeltests/custom_managers/models.py
@@ -18,8 +18,8 @@ def get_fun_people(self):
return self.filter(fun=True)
class Person(models.Model):
- first_name = models.CharField(maxlength=30)
- last_name = models.CharField(maxlength=30)
+ first_name = models.CharField(max_length=30)
+ last_name = models.CharField(max_length=30)
fun = models.BooleanField()
objects = PersonManager()
@@ -33,8 +33,8 @@ def get_query_set(self):
return super(PublishedBookManager, self).get_query_set().filter(is_published=True)
class Book(models.Model):
- title = models.CharField(maxlength=50)
- author = models.CharField(maxlength=30)
+ title = models.CharField(max_length=50)
+ author = models.CharField(max_length=30)
is_published = models.BooleanField()
published_objects = PublishedBookManager()
authors = models.ManyToManyField(Person, related_name='books')
@@ -49,7 +49,7 @@ def get_query_set(self):
return super(FastCarManager, self).get_query_set().filter(top_speed__gt=150)
class Car(models.Model):
- name = models.CharField(maxlength=10)
+ name = models.CharField(max_length=10)
mileage = models.IntegerField()
top_speed = models.IntegerField(help_text="In miles per hour.")
cars = models.Manager()
View
2  tests/modeltests/custom_methods/models.py
@@ -8,7 +8,7 @@
import datetime
class Article(models.Model):
- headline = models.CharField(maxlength=100)
+ headline = models.CharField(max_length=100)
pub_date = models.DateField()
def __unicode__(self):
View
8 tests/modeltests/custom_pk/models.py
@@ -8,10 +8,10 @@
from django.db import models
class Employee(models.Model):
- employee_code = models.CharField(maxlength=10, primary_key=True,
+ employee_code = models.CharField(max_length=10, primary_key=True,
db_column = 'code')
- first_name = models.CharField(maxlength=20)
- last_name = models.CharField(maxlength=20)
+ first_name = models.CharField(max_length=20)
+ last_name = models.CharField(max_length=20)
class Meta:
ordering = ('last_name', 'first_name')
@@ -19,7 +19,7 @@ def __unicode__(self):
return u"%s %s" % (self.first_name, self.last_name)
class Business(models.Model):
- name = models.CharField(maxlength=20, primary_key=True)
+ name = models.CharField(max_length=20, primary_key=True)
employees = models.ManyToManyField(Employee)
class Meta:
verbose_name_plural = 'businesses'
View
2  tests/modeltests/field_defaults/models.py
@@ -13,7 +13,7 @@
from datetime import datetime
class Article(models.Model):
- headline = models.CharField(maxlength=100, default='Default headline')
+ headline = models.CharField(max_length=100, default='Default headline')
pub_date = models.DateTimeField(default=datetime.now)
def __unicode__(self):
View
2  tests/modeltests/fixtures/models.py
@@ -11,7 +11,7 @@
from django.db import models
class Article(models.Model):
- headline = models.CharField(maxlength=100, default='Default headline')
+ headline = models.CharField(max_length=100, default='Default headline')
pub_date = models.DateTimeField()
def __unicode__(self):
View
8 tests/modeltests/generic_relations/models.py
@@ -28,8 +28,8 @@ def __unicode__(self):
return self.tag
class Animal(models.Model):
- common_name = models.CharField(maxlength=150)
- latin_name = models.CharField(maxlength=150)
+ common_name = models.CharField(max_length=150)
+ latin_name = models.CharField(max_length=150)
tags = generic.GenericRelation(TaggedItem)
@@ -37,7 +37,7 @@ def __unicode__(self):
return self.common_name
class Vegetable(models.Model):
- name = models.CharField(maxlength=150)
+ name = models.CharField(max_length=150)
is_yucky = models.BooleanField(default=True)
tags = generic.GenericRelation(TaggedItem)
@@ -46,7 +46,7 @@ def __unicode__(self):
return self.name
class Mineral(models.Model):
- name = models.CharField(maxlength=150)
+ name = models.CharField(max_length=150)
hardness = models.PositiveSmallIntegerField()
# note the lack of an explicit GenericRelation here...
View
4 tests/modeltests/get_latest/models.py
@@ -11,7 +11,7 @@
from django.db import models
class Article(models.Model):
- headline = models.CharField(maxlength=100)
+ headline = models.CharField(max_length=100)
pub_date = models.DateField()
expire_date = models.DateField()
class Meta:
@@ -21,7 +21,7 @@ def __unicode__(self):
return self.headline
class Person(models.Model):
- name = models.CharField(maxlength=30)
+ name = models.CharField(max_length=30)
birthday = models.DateField()
# Note that this model doesn't have "get_latest_by" set.
View
4 tests/