Ticket #2101: max_length+docs.patch

File max_length+docs.patch, 107.6 KB (added by Marc Fargas <telenieko@…>, 17 years ago)

The same as above, with extra note in mode-api.txt

  • django/db/models/fields/__init__.py

     
    4141        return
    4242    raise validators.ValidationError, gettext("%(optname)s with this %(fieldname)s already exists.") % {'optname': capfirst(opts.verbose_name), 'fieldname': f.verbose_name}
    4343
     44# Methods for legacy maxlength support.
     45def get_maxlength(self):
     46    return self.max_length
     47def set_maxlength(self, value):
     48    self.max_length = value
     49def legacy_maxlength(max_length, maxlength):
     50    if maxlength is not None:
     51        if max_length is not None:
     52            raise TypeError, 'field can not take both the max_length argument and the legacy maxlength argument'
     53        max_length = maxlength
     54    return max_length
     55
    4456# A guide to Field parameters:
    4557#
    4658#   * name:      The name of the field specifed in the model.
     
    6678    creation_counter = 0
    6779
    6880    def __init__(self, verbose_name=None, name=None, primary_key=False,
    69         maxlength=None, unique=False, blank=False, null=False, db_index=False,
     81        max_length=None, unique=False, blank=False, null=False, db_index=False,
    7082        core=False, rel=None, default=NOT_PROVIDED, editable=True,
    7183        prepopulate_from=None, unique_for_date=None, unique_for_month=None,
    7284        unique_for_year=None, validator_list=None, choices=None, radio_admin=None,
    73         help_text='', db_column=None):
     85        help_text='', db_column=None, maxlength=None):
    7486        self.name = name
    7587        self.verbose_name = verbose_name
    7688        self.primary_key = primary_key
    77         self.maxlength, self.unique = maxlength, unique
     89        # Fields now use max_length, but still support the legacy maxlength argument.
     90        self.max_length = legacy_maxlength(max_length=max_length, maxlength=maxlength)
     91        self.unique = unique
    7892        self.blank, self.null = blank, null
    7993        self.core, self.rel, self.default = core, rel, default
    8094        self.editable = editable
     
    94108        self.creation_counter = Field.creation_counter
    95109        Field.creation_counter += 1
    96110
     111    # Support accessing and setting to the legacy maxlength argument.
     112    maxlength = property(get_maxlength, set_maxlength)
     113
    97114    def __cmp__(self, other):
    98115        # This is needed because bisect does not take a comparison function.
    99116        return cmp(self.creation_counter, other.creation_counter)
     
    202219
    203220    def prepare_field_objs_and_params(self, manipulator, name_prefix):
    204221        params = {'validator_list': self.validator_list[:]}
    205         if self.maxlength and not self.choices: # Don't give SelectFields a maxlength parameter.
    206             params['maxlength'] = self.maxlength
     222        if self.max_length and not self.choices: # Don't give SelectFields a max_length parameter.
     223            params['max_length'] = self.max_length
    207224
    208225        if self.choices:
    209226            if self.radio_admin:
     
    417434        return str(value)
    418435
    419436    def formfield(self, **kwargs):
    420         defaults = {'max_length': self.maxlength, 'required': not self.blank, 'label': capfirst(self.verbose_name)}
     437        defaults = {'max_length': self.max_length, 'required': not self.blank, 'label': capfirst(self.verbose_name)}
    421438        defaults.update(kwargs)
    422439        return forms.CharField(**defaults)
    423440
     
    562579
    563580class EmailField(CharField):
    564581    def __init__(self, *args, **kwargs):
    565         kwargs['maxlength'] = 75
     582        kwargs['max_length'] = 75
    566583        CharField.__init__(self, *args, **kwargs)
    567584
    568585    def get_internal_type(self):
     
    718735
    719736class IPAddressField(Field):
    720737    def __init__(self, *args, **kwargs):
    721         kwargs['maxlength'] = 15
     738        kwargs['max_length'] = 15
    722739        Field.__init__(self, *args, **kwargs)
    723740
    724741    def get_manipulator_field_objs(self):
     
    752769
    753770class SlugField(Field):
    754771    def __init__(self, *args, **kwargs):
    755         kwargs['maxlength'] = kwargs.get('maxlength', 50)
     772        kwargs['max_length'] = kwargs.get('max_length', 50)
    756773        kwargs.setdefault('validator_list', []).append(validators.isSlug)
    757774        # Set db_index=True unless it's been set manually.
    758775        if not kwargs.has_key('db_index'):
     
    822839
    823840class URLField(CharField):
    824841    def __init__(self, verbose_name=None, name=None, verify_exists=True, **kwargs):
    825         kwargs['maxlength'] = kwargs.get('maxlength', 200)
     842        kwargs['max_length'] = kwargs.get('max_length', 200)
    826843        if verify_exists:
    827844            kwargs.setdefault('validator_list', []).append(validators.isExistingURL)
    828845        self.verify_exists = verify_exists
  • django/db/backends/ado_mssql/creation.py

     
    11DATA_TYPES = {
    22    'AutoField':         'int IDENTITY (1, 1)',
    33    'BooleanField':      'bit',
    4     'CharField':         'varchar(%(maxlength)s)',
    5     'CommaSeparatedIntegerField': 'varchar(%(maxlength)s)',
     4    'CharField':         'varchar(%(max_length)s)',
     5    'CommaSeparatedIntegerField': 'varchar(%(max_length)s)',
    66    'DateField':         'smalldatetime',
    77    'DateTimeField':     'smalldatetime',
    88    'FileField':         'varchar(100)',
     
    1717    'PhoneNumberField':  'varchar(20)',
    1818    'PositiveIntegerField': 'int CONSTRAINT [CK_int_pos_%(column)s] CHECK ([%(column)s] > 0)',
    1919    'PositiveSmallIntegerField': 'smallint CONSTRAINT [CK_smallint_pos_%(column)s] CHECK ([%(column)s] > 0)',
    20     'SlugField':         'varchar(%(maxlength)s)',
     20    'SlugField':         'varchar(%(max_length)s)',
    2121    'SmallIntegerField': 'smallint',
    2222    'TextField':         'text',
    2323    'TimeField':         'time',
  • django/db/backends/postgresql/creation.py

     
    55DATA_TYPES = {
    66    'AutoField':         'serial',
    77    'BooleanField':      'boolean',
    8     'CharField':         'varchar(%(maxlength)s)',
    9     'CommaSeparatedIntegerField': 'varchar(%(maxlength)s)',
     8    'CharField':         'varchar(%(max_length)s)',
     9    'CommaSeparatedIntegerField': 'varchar(%(max_length)s)',
    1010    'DateField':         'date',
    1111    'DateTimeField':     'timestamp with time zone',
    1212    'FileField':         'varchar(100)',
     
    2121    'PhoneNumberField':  'varchar(20)',
    2222    'PositiveIntegerField': 'integer CHECK ("%(column)s" >= 0)',
    2323    'PositiveSmallIntegerField': 'smallint CHECK ("%(column)s" >= 0)',
    24     'SlugField':         'varchar(%(maxlength)s)',
     24    'SlugField':         'varchar(%(max_length)s)',
    2525    'SmallIntegerField': 'smallint',
    2626    'TextField':         'text',
    2727    'TimeField':         'time',
  • django/db/backends/sqlite3/introspection.py

     
    8181            import re
    8282            m = re.search(r'^\s*(?:var)?char\s*\(\s*(\d+)\s*\)\s*$', key)
    8383            if m:
    84                 return ('CharField', {'maxlength': int(m.group(1))})
     84                return ('CharField', {'max_length': int(m.group(1))})
    8585            raise KeyError
    8686
    8787DATA_TYPES_REVERSE = FlexibleFieldLookupDict()
  • django/db/backends/sqlite3/creation.py

     
    44DATA_TYPES = {
    55    'AutoField':                    'integer',
    66    'BooleanField':                 'bool',
    7     'CharField':                    'varchar(%(maxlength)s)',
    8     'CommaSeparatedIntegerField':   'varchar(%(maxlength)s)',
     7    'CharField':                    'varchar(%(max_length)s)',
     8    'CommaSeparatedIntegerField':   'varchar(%(max_length)s)',
    99    'DateField':                    'date',
    1010    'DateTimeField':                'datetime',
    1111    'FileField':                    'varchar(100)',
     
    2020    'PhoneNumberField':             'varchar(20)',
    2121    'PositiveIntegerField':         'integer unsigned',
    2222    'PositiveSmallIntegerField':    'smallint unsigned',
    23     'SlugField':                    'varchar(%(maxlength)s)',
     23    'SlugField':                    'varchar(%(max_length)s)',
    2424    'SmallIntegerField':            'smallint',
    2525    'TextField':                    'text',
    2626    'TimeField':                    'time',
  • django/db/backends/mysql/creation.py

     
    55DATA_TYPES = {
    66    'AutoField':         'integer AUTO_INCREMENT',
    77    'BooleanField':      'bool',
    8     'CharField':         'varchar(%(maxlength)s)',
    9     'CommaSeparatedIntegerField': 'varchar(%(maxlength)s)',
     8    'CharField':         'varchar(%(max_length)s)',
     9    'CommaSeparatedIntegerField': 'varchar(%(max_length)s)',
    1010    'DateField':         'date',
    1111    'DateTimeField':     'datetime',
    1212    'FileField':         'varchar(100)',
     
    2121    'PhoneNumberField':  'varchar(20)',
    2222    'PositiveIntegerField': 'integer UNSIGNED',
    2323    'PositiveSmallIntegerField': 'smallint UNSIGNED',
    24     'SlugField':         'varchar(%(maxlength)s)',
     24    'SlugField':         'varchar(%(max_length)s)',
    2525    'SmallIntegerField': 'smallint',
    2626    'TextField':         'longtext',
    2727    'TimeField':         'time',
  • django/db/backends/oracle/creation.py

     
    11DATA_TYPES = {
    22    'AutoField':         'number(38)',
    33    'BooleanField':      'number(1)',
    4     'CharField':         'varchar2(%(maxlength)s)',
    5     'CommaSeparatedIntegerField': 'varchar2(%(maxlength)s)',
     4    'CharField':         'varchar2(%(max_length)s)',
     5    'CommaSeparatedIntegerField': 'varchar2(%(max_length)s)',
    66    'DateField':         'date',
    77    'DateTimeField':     'date',
    88    'FileField':         'varchar2(100)',
  • django/oldforms/__init__.py

     
    371371# GENERIC WIDGETS  #
    372372####################
    373373
     374# Methods for legacy maxlength support.
     375def get_maxlength(self):
     376    return self.max_length
     377def set_maxlength(self, value):
     378    self.max_length = value
     379def legacy_maxlength(max_length, maxlength, has_default=False):
     380    """
     381    Override new max_length attribute with legacy maxlength if it has been given.
     382    An error will be raised if both attributes are given. To avoid this (which the
     383    normal case is that new max_length has been given a default value) set
     384    has_default to True.
     385    """
     386    if maxlength is not None:
     387        if max_length is not None and not has_default:
     388            raise TypeError, 'field can not take both the max_length argument and the legacy maxlength argument'
     389        max_length = maxlength
     390    return max_length
     391
    374392class TextField(FormField):
    375393    input_type = "text"
    376     def __init__(self, field_name, length=30, maxlength=None, is_required=False, validator_list=None, member_name=None):
     394    def __init__(self, field_name, length=30, max_length=None, is_required=False, validator_list=None, member_name=None, maxlength=None):
    377395        if validator_list is None: validator_list = []
    378396        self.field_name = field_name
    379         self.length, self.maxlength = length, maxlength
     397        self.length = length
     398        # Fields now use max_length, but still support the legacy maxlength argument.
     399        self.max_length = legacy_maxlength(max_length=max_length, maxlength=maxlength)
    380400        self.is_required = is_required
    381401        self.validator_list = [self.isValidLength, self.hasNoNewlines] + validator_list
    382402        if member_name != None:
    383403            self.member_name = member_name
    384404
     405    # Support accessing and setting the legacy maxlength argument.
     406    maxlength = property(get_maxlength, set_maxlength)
     407
    385408    def isValidLength(self, data, form):
    386         if data and self.maxlength and len(data.decode(settings.DEFAULT_CHARSET)) > self.maxlength:
     409        if data and self.max_length and len(data.decode(settings.DEFAULT_CHARSET)) > self.max_length:
    387410            raise validators.ValidationError, ngettext("Ensure your text is less than %s character.",
    388                 "Ensure your text is less than %s characters.", self.maxlength) % self.maxlength
     411                "Ensure your text is less than %s characters.", self.max_length) % self.max_length
    389412
    390413    def hasNoNewlines(self, data, form):
    391414        if data and '\n' in data:
     
    394417    def render(self, data):
    395418        if data is None:
    396419            data = ''
    397         maxlength = ''
    398         if self.maxlength:
    399             maxlength = 'maxlength="%s" ' % self.maxlength
     420        max_length = ''
     421        if self.max_length:
     422            max_length = 'maxlength="%s" ' % self.max_length
    400423        if isinstance(data, unicode):
    401424            data = data.encode(settings.DEFAULT_CHARSET)
    402425        return '<input type="%s" id="%s" class="v%s%s" name="%s" size="%s" value="%s" %s/>' % \
    403426            (self.input_type, self.get_id(), self.__class__.__name__, self.is_required and ' required' or '',
    404             self.field_name, self.length, escape(data), maxlength)
     427            self.field_name, self.length, escape(data), max_length)
    405428
    406429    def html2python(data):
    407430        return data
     
    411434    input_type = "password"
    412435
    413436class LargeTextField(TextField):
    414     def __init__(self, field_name, rows=10, cols=40, is_required=False, validator_list=None, maxlength=None):
     437    def __init__(self, field_name, rows=10, cols=40, is_required=False, validator_list=None, max_length=None, maxlength=None):
     438        max_length = legacy_maxlength(max_length=max_length, maxlength=maxlength)
    415439        if validator_list is None: validator_list = []
    416440        self.field_name = field_name
    417441        self.rows, self.cols, self.is_required = rows, cols, is_required
    418442        self.validator_list = validator_list[:]
    419         if maxlength:
     443        if max_length:
    420444            self.validator_list.append(self.isValidLength)
    421             self.maxlength = maxlength
     445            self.max_length = max_length
    422446
    423447    def render(self, data):
    424448        if data is None:
     
    695719####################
    696720
    697721class IntegerField(TextField):
    698     def __init__(self, field_name, length=10, maxlength=None, is_required=False, validator_list=None, member_name=None):
     722    def __init__(self, field_name, length=10, max_length=None, is_required=False, validator_list=None, member_name=None, maxlength=None):
     723        max_length = legacy_maxlength(max_length=max_length, maxlength=maxlength)
    699724        if validator_list is None: validator_list = []
    700725        validator_list = [self.isInteger] + validator_list
    701726        if member_name is not None:
    702727            self.member_name = member_name
    703         TextField.__init__(self, field_name, length, maxlength, is_required, validator_list)
     728        TextField.__init__(self, field_name, length, max_length, is_required, validator_list)
    704729
    705730    def isInteger(self, field_data, all_data):
    706731        try:
     
    715740    html2python = staticmethod(html2python)
    716741
    717742class SmallIntegerField(IntegerField):
    718     def __init__(self, field_name, length=5, maxlength=5, is_required=False, validator_list=None):
     743    def __init__(self, field_name, length=5, max_length=5, is_required=False, validator_list=None, maxlength=None):
     744        max_length = legacy_maxlength(max_length=max_length, maxlength=maxlength, has_default=True)
    719745        if validator_list is None: validator_list = []
    720746        validator_list = [self.isSmallInteger] + validator_list
    721         IntegerField.__init__(self, field_name, length, maxlength, is_required, validator_list)
     747        IntegerField.__init__(self, field_name, length, max_length, is_required, validator_list)
    722748
    723749    def isSmallInteger(self, field_data, all_data):
    724750        if not -32768 <= int(field_data) <= 32767:
    725751            raise validators.CriticalValidationError, gettext("Enter a whole number between -32,768 and 32,767.")
    726752
    727753class PositiveIntegerField(IntegerField):
    728     def __init__(self, field_name, length=10, maxlength=None, is_required=False, validator_list=None):
     754    def __init__(self, field_name, length=10, max_length=None, is_required=False, validator_list=None, maxlength=None):
     755        max_length = legacy_maxlength(max_length=max_length, maxlength=maxlength)
    729756        if validator_list is None: validator_list = []
    730757        validator_list = [self.isPositive] + validator_list
    731         IntegerField.__init__(self, field_name, length, maxlength, is_required, validator_list)
     758        IntegerField.__init__(self, field_name, length, max_length, is_required, validator_list)
    732759
    733760    def isPositive(self, field_data, all_data):
    734761        if int(field_data) < 0:
    735762            raise validators.CriticalValidationError, gettext("Enter a positive number.")
    736763
    737764class PositiveSmallIntegerField(IntegerField):
    738     def __init__(self, field_name, length=5, maxlength=None, is_required=False, validator_list=None):
     765    def __init__(self, field_name, length=5, max_length=None, is_required=False, validator_list=None, maxlength=None):
     766        max_length = legacy_maxlength(max_length=max_length, maxlength=maxlength)
    739767        if validator_list is None: validator_list = []
    740768        validator_list = [self.isPositiveSmall] + validator_list
    741         IntegerField.__init__(self, field_name, length, maxlength, is_required, validator_list)
     769        IntegerField.__init__(self, field_name, length, max_length, is_required, validator_list)
    742770
    743771    def isPositiveSmall(self, field_data, all_data):
    744772        if not 0 <= int(field_data) <= 32767:
     
    771799class DatetimeField(TextField):
    772800    """A FormField that automatically converts its data to a datetime.datetime object.
    773801    The data should be in the format YYYY-MM-DD HH:MM:SS."""
    774     def __init__(self, field_name, length=30, maxlength=None, is_required=False, validator_list=None):
     802    def __init__(self, field_name, length=30, max_length=None, is_required=False, validator_list=None, maxlength=None):
     803        max_length = legacy_maxlength(max_length=max_length, maxlength=maxlength)
    775804        if validator_list is None: validator_list = []
    776805        self.field_name = field_name
    777         self.length, self.maxlength = length, maxlength
     806        self.length, self.max_length = length, max_length
    778807        self.is_required = is_required
    779808        self.validator_list = [validators.isValidANSIDatetime] + validator_list
    780809
     
    801830    def __init__(self, field_name, is_required=False, validator_list=None):
    802831        if validator_list is None: validator_list = []
    803832        validator_list = [self.isValidDate] + validator_list
    804         TextField.__init__(self, field_name, length=10, maxlength=10,
     833        TextField.__init__(self, field_name, length=10, max_length=10,
    805834            is_required=is_required, validator_list=validator_list)
    806835
    807836    def isValidDate(self, field_data, all_data):
     
    826855    def __init__(self, field_name, is_required=False, validator_list=None):
    827856        if validator_list is None: validator_list = []
    828857        validator_list = [self.isValidTime] + validator_list
    829         TextField.__init__(self, field_name, length=8, maxlength=8,
     858        TextField.__init__(self, field_name, length=8, max_length=8,
    830859            is_required=is_required, validator_list=validator_list)
    831860
    832861    def isValidTime(self, field_data, all_data):
     
    858887
    859888class EmailField(TextField):
    860889    "A convenience FormField for validating e-mail addresses"
    861     def __init__(self, field_name, length=50, maxlength=75, is_required=False, validator_list=None):
     890    def __init__(self, field_name, length=50, max_length=75, is_required=False, validator_list=None, maxlength=None):
     891        max_length = legacy_maxlength(max_length=max_length, maxlength=maxlength, has_default=True)
    862892        if validator_list is None: validator_list = []
    863893        validator_list = [self.isValidEmail] + validator_list
    864         TextField.__init__(self, field_name, length, maxlength=maxlength,
     894        TextField.__init__(self, field_name, length, max_length=max_length,
    865895            is_required=is_required, validator_list=validator_list)
    866896
    867897    def isValidEmail(self, field_data, all_data):
     
    872902
    873903class URLField(TextField):
    874904    "A convenience FormField for validating URLs"
    875     def __init__(self, field_name, length=50, maxlength=200, is_required=False, validator_list=None):
     905    def __init__(self, field_name, length=50, max_length=200, is_required=False, validator_list=None, maxlength=None):
     906        max_length = legacy_maxlength(max_length=max_length, maxlength=maxlength, has_default=True)
    876907        if validator_list is None: validator_list = []
    877908        validator_list = [self.isValidURL] + validator_list
    878         TextField.__init__(self, field_name, length=length, maxlength=maxlength,
     909        TextField.__init__(self, field_name, length=length, max_length=max_length,
    879910            is_required=is_required, validator_list=validator_list)
    880911
    881912    def isValidURL(self, field_data, all_data):
     
    885916            raise validators.CriticalValidationError, e.messages
    886917
    887918class IPAddressField(TextField):
    888     def __init__(self, field_name, length=15, maxlength=15, is_required=False, validator_list=None):
     919    def __init__(self, field_name, length=15, max_length=15, is_required=False, validator_list=None, maxlength=None):
     920        max_length = legacy_maxlength(max_length=max_length, maxlength=maxlength, has_default=True)
    889921        if validator_list is None: validator_list = []
    890922        validator_list = [self.isValidIPAddress] + validator_list
    891         TextField.__init__(self, field_name, length=length, maxlength=maxlength,
     923        TextField.__init__(self, field_name, length=length, max_length=max_length,
    892924            is_required=is_required, validator_list=validator_list)
    893925
    894926    def isValidIPAddress(self, field_data, all_data):
     
    934966    def __init__(self, field_name, is_required=False, validator_list=None):
    935967        if validator_list is None: validator_list = []
    936968        validator_list = [self.isValidPhone] + validator_list
    937         TextField.__init__(self, field_name, length=12, maxlength=12,
     969        TextField.__init__(self, field_name, length=12, max_length=12,
    938970            is_required=is_required, validator_list=validator_list)
    939971
    940972    def isValidPhone(self, field_data, all_data):
     
    948980    def __init__(self, field_name, is_required=False, validator_list=None):
    949981        if validator_list is None: validator_list = []
    950982        validator_list = [self.isValidUSState] + validator_list
    951         TextField.__init__(self, field_name, length=2, maxlength=2,
     983        TextField.__init__(self, field_name, length=2, max_length=2,
    952984            is_required=is_required, validator_list=validator_list)
    953985
    954986    def isValidUSState(self, field_data, all_data):
     
    963995
    964996class CommaSeparatedIntegerField(TextField):
    965997    "A convenience FormField for validating comma-separated integer fields"
    966     def __init__(self, field_name, maxlength=None, is_required=False, validator_list=None):
     998    def __init__(self, field_name, max_length=None, is_required=False, validator_list=None, maxlength=None):
     999        max_length = legacy_maxlength(max_length=max_length, maxlength=maxlength)
    9671000        if validator_list is None: validator_list = []
    9681001        validator_list = [self.isCommaSeparatedIntegerList] + validator_list
    969         TextField.__init__(self, field_name, length=20, maxlength=maxlength,
     1002        TextField.__init__(self, field_name, length=20, max_length=max_length,
    9701003            is_required=is_required, validator_list=validator_list)
    9711004
    9721005    def isCommaSeparatedIntegerList(self, field_data, all_data):
  • django/core/management.py

     
    800800                    field_type, new_params = field_type
    801801                    extra_params.update(new_params)
    802802
    803                 # Add maxlength for all CharFields.
     803                # Add max_length for all CharFields.
    804804                if field_type == 'CharField' and row[3]:
    805                     extra_params['maxlength'] = row[3]
     805                    extra_params['max_length'] = row[3]
    806806
    807807                if field_type == 'FloatField':
    808808                    extra_params['max_digits'] = row[4]
     
    877877        for f in opts.fields:
    878878            if f.name == 'id' and not f.primary_key and opts.pk.name == 'id':
    879879                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)
    880             if isinstance(f, models.CharField) and f.maxlength in (None, 0):
    881                 e.add(opts, '"%s": CharFields require a "maxlength" attribute.' % f.name)
     880            if isinstance(f, models.CharField) and f.max_length in (None, 0):
     881                e.add(opts, '"%s": CharFields require a "max_length" attribute.' % f.name)
    882882            if isinstance(f, models.FloatField):
    883883                if f.decimal_places is None:
    884884                    e.add(opts, '"%s": FloatFields require a "decimal_places" attribute.' % f.name)
     
    903903            if f.db_index not in (None, True, False):
    904904                e.add(opts, '"%s": "db_index" should be either None, True or False.' % f.name)
    905905
    906             # Check that maxlength <= 255 if using older MySQL versions.
     906            # Check that max_length <= 255 if using older MySQL versions.
    907907            if settings.DATABASE_ENGINE == 'mysql':
    908908                db_version = connection.get_server_version()
    909                 if db_version < (5, 0, 3) and isinstance(f, (models.CharField, models.CommaSeparatedIntegerField, models.SlugField)) and f.maxlength > 255:
    910                     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]])))
     909                if db_version < (5, 0, 3) and isinstance(f, (models.CharField, models.CommaSeparatedIntegerField, models.SlugField)) and f.max_length > 255:
     910                    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]])))
    911911
    912912            # Check to see if the related field will clash with any
    913913            # existing fields, m2m fields, m2m related objects or related objects
     
    11421142    data_types = get_creation_module().DATA_TYPES
    11431143    fields = (
    11441144        # "key" is a reserved word in MySQL, so use "cache_key" instead.
    1145         models.CharField(name='cache_key', maxlength=255, unique=True, primary_key=True),
     1145        models.CharField(name='cache_key', max_length=255, unique=True, primary_key=True),
    11461146        models.TextField(name='value'),
    11471147        models.DateTimeField(name='expires', db_index=True),
    11481148    )
  • django/contrib/redirects/models.py

     
    44
    55class Redirect(models.Model):
    66    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,
    88        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,
    1010        help_text=_("This can be either an absolute path (as above) or a full URL starting with 'http://'."))
    1111
    1212    class Meta:
  • django/contrib/comments/models.py

     
    6565    user = models.ForeignKey(User, raw_id_admin=True)
    6666    content_type = models.ForeignKey(ContentType)
    6767    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)
    7070    rating1 = models.PositiveSmallIntegerField(_('rating #1'), blank=True, null=True)
    7171    rating2 = models.PositiveSmallIntegerField(_('rating #2'), blank=True, null=True)
    7272    rating3 = models.PositiveSmallIntegerField(_('rating #3'), blank=True, null=True)
     
    164164    # A FreeComment is a comment by a non-registered user.
    165165    content_type = models.ForeignKey(ContentType)
    166166    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)
    169169    submit_date = models.DateTimeField(_('date/time submitted'), auto_now_add=True)
    170170    is_public = models.BooleanField(_('is public'))
    171171    ip_address = models.IPAddressField(_('ip address'))
  • django/contrib/comments/views/comments.py

     
    2828            else:
    2929                return []
    3030        self.fields.extend([
    31             oldforms.LargeTextField(field_name="comment", maxlength=3000, is_required=True,
     31            oldforms.LargeTextField(field_name="comment", max_length=3000, is_required=True,
    3232                validator_list=[self.hasNoProfanities]),
    3333            oldforms.RadioSelectField(field_name="rating1", choices=choices,
    3434                is_required=ratings_required and num_rating_choices > 0,
     
    121121    "Manipulator that handles public free (unregistered) comments"
    122122    def __init__(self):
    123123        self.fields = (
    124             oldforms.TextField(field_name="person_name", maxlength=50, is_required=True,
     124            oldforms.TextField(field_name="person_name", max_length=50, is_required=True,
    125125                validator_list=[self.hasNoProfanities]),
    126             oldforms.LargeTextField(field_name="comment", maxlength=3000, is_required=True,
     126            oldforms.LargeTextField(field_name="comment", max_length=3000, is_required=True,
    127127                validator_list=[self.hasNoProfanities]),
    128128        )
    129129
  • django/contrib/sites/models.py

     
    77        return self.get(pk=settings.SITE_ID)
    88
    99class Site(models.Model):
    10     domain = models.CharField(_('domain name'), maxlength=100)
    11     name = models.CharField(_('display name'), maxlength=50)
     10    domain = models.CharField(_('domain name'), max_length=100)
     11    name = models.CharField(_('display name'), max_length=50)
    1212    objects = SiteManager()
    1313    class Meta:
    1414        db_table = 'django_site'
  • django/contrib/admin/templatetags/admin_modify.py

     
    189189            t.append('document.getElementById("id_%s").onkeyup = function() {' \
    190190                     ' var e = document.getElementById("id_%s");' \
    191191                     ' if(!e._changed) { e.value = URLify(%s, %s);} }; ' % (
    192                      f, field.name, add_values, field.maxlength))
     192                     f, field.name, add_values, field.max_length))
    193193    return ''.join(t)
    194194auto_populated_field_script = register.simple_tag(auto_populated_field_script)
    195195
  • django/contrib/admin/models.py

     
    1717    user = models.ForeignKey(User)
    1818    content_type = models.ForeignKey(ContentType, blank=True, null=True)
    1919    object_id = models.TextField(_('object id'), blank=True, null=True)
    20     object_repr = models.CharField(_('object repr'), maxlength=200)
     20    object_repr = models.CharField(_('object repr'), max_length=200)
    2121    action_flag = models.PositiveSmallIntegerField(_('action flag'))
    2222    change_message = models.TextField(_('change message'), blank=True)
    2323    objects = LogEntryManager()
  • django/contrib/admin/views/doc.py

     
    290290DATA_TYPE_MAPPING = {
    291291    'AutoField'                 : _('Integer'),
    292292    'BooleanField'              : _('Boolean (Either True or False)'),
    293     'CharField'                 : _('String (up to %(maxlength)s)'),
     293    'CharField'                 : _('String (up to %(max_length)s)'),
    294294    'CommaSeparatedIntegerField': _('Comma-separated integers'),
    295295    'DateField'                 : _('Date (without time)'),
    296296    'DateTimeField'             : _('Date (with time)'),
     
    308308    'PhoneNumberField'          : _('Phone number'),
    309309    'PositiveIntegerField'      : _('Integer'),
    310310    'PositiveSmallIntegerField' : _('Integer'),
    311     'SlugField'                 : _('String (up to %(maxlength)s)'),
     311    'SlugField'                 : _('String (up to %(max_length)s)'),
    312312    'SmallIntegerField'         : _('Integer'),
    313313    'TextField'                 : _('Text'),
    314314    'TimeField'                 : _('Time'),
  • django/contrib/contenttypes/models.py

     
    2121        return ct
    2222
    2323class ContentType(models.Model):
    24     name = models.CharField(maxlength=100)
    25     app_label = models.CharField(maxlength=100)
    26     model = models.CharField(_('python model class name'), maxlength=100)
     24    name = models.CharField(max_length=100)
     25    app_label = models.CharField(max_length=100)
     26    model = models.CharField(_('python model class name'), max_length=100)
    2727    objects = ContentTypeManager()
    2828    class Meta:
    2929        verbose_name = _('content type')
  • django/contrib/auth/models.py

     
    3535
    3636    Three basic permissions -- add, change and delete -- are automatically created for each Django model.
    3737    """
    38     name = models.CharField(_('name'), maxlength=50)
     38    name = models.CharField(_('name'), max_length=50)
    3939    content_type = models.ForeignKey(ContentType)
    40     codename = models.CharField(_('codename'), maxlength=100)
     40    codename = models.CharField(_('codename'), max_length=100)
    4141    class Meta:
    4242        verbose_name = _('permission')
    4343        verbose_name_plural = _('permissions')
     
    5454
    5555    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.
    5656    """
    57     name = models.CharField(_('name'), maxlength=80, unique=True)
     57    name = models.CharField(_('name'), max_length=80, unique=True)
    5858    permissions = models.ManyToManyField(Permission, verbose_name=_('permissions'), blank=True, filter_interface=models.HORIZONTAL)
    5959    class Meta:
    6060        verbose_name = _('group')
     
    8787
    8888    Username and password are required. Other fields are optional.
    8989    """
    90     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)."))
    91     first_name = models.CharField(_('first name'), maxlength=30, blank=True)
    92     last_name = models.CharField(_('last name'), maxlength=30, blank=True)
     90    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)."))
     91    first_name = models.CharField(_('first name'), max_length=30, blank=True)
     92    last_name = models.CharField(_('last name'), max_length=30, blank=True)
    9393    email = models.EmailField(_('e-mail address'), blank=True)
    94     password = models.CharField(_('password'), maxlength=128, help_text=_("Use '[algo]$[salt]$[hexdigest]' or use the <a href=\"password/\">change password form</a>."))
     94    password = models.CharField(_('password'), max_length=128, help_text=_("Use '[algo]$[salt]$[hexdigest]' or use the <a href=\"password/\">change password form</a>."))
    9595    is_staff = models.BooleanField(_('staff status'), default=False, help_text=_("Designates whether the user can log into this admin site."))
    9696    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."))
    9797    is_superuser = models.BooleanField(_('superuser status'), default=False, help_text=_("Designates that this user has all permissions without explicitly assigning them."))
  • django/contrib/auth/forms.py

     
    99    "A form that creates a user, with no privileges, from the given username and password."
    1010    def __init__(self):
    1111        self.fields = (
    12             oldforms.TextField(field_name='username', length=30, maxlength=30, is_required=True,
     12            oldforms.TextField(field_name='username', length=30, max_length=30, is_required=True,
    1313                validator_list=[validators.isAlphaNumeric, self.isValidUsername]),
    14             oldforms.PasswordField(field_name='password1', length=30, maxlength=60, is_required=True),
    15             oldforms.PasswordField(field_name='password2', length=30, maxlength=60, is_required=True,
     14            oldforms.PasswordField(field_name='password1', length=30, max_length=60, is_required=True),
     15            oldforms.PasswordField(field_name='password2', length=30, max_length=60, is_required=True,
    1616                validator_list=[validators.AlwaysMatchesOtherField('password1', _("The two password fields didn't match."))]),
    1717        )
    1818
     
    4141        """
    4242        self.request = request
    4343        self.fields = [
    44             oldforms.TextField(field_name="username", length=15, maxlength=30, is_required=True,
     44            oldforms.TextField(field_name="username", length=15, max_length=30, is_required=True,
    4545                validator_list=[self.isValidUser, self.hasCookiesEnabled]),
    46             oldforms.PasswordField(field_name="password", length=15, maxlength=30, is_required=True),
     46            oldforms.PasswordField(field_name="password", length=15, max_length=30, is_required=True),
    4747        ]
    4848        self.user_cache = None
    4949
     
    110110    def __init__(self, user):
    111111        self.user = user
    112112        self.fields = (
    113             oldforms.PasswordField(field_name="old_password", length=30, maxlength=30, is_required=True,
     113            oldforms.PasswordField(field_name="old_password", length=30, max_length=30, is_required=True,
    114114                validator_list=[self.isValidOldPassword]),
    115             oldforms.PasswordField(field_name="new_password1", length=30, maxlength=30, is_required=True,
     115            oldforms.PasswordField(field_name="new_password1", length=30, max_length=30, is_required=True,
    116116                validator_list=[validators.AlwaysMatchesOtherField('new_password2', _("The two 'new password' fields didn't match."))]),
    117             oldforms.PasswordField(field_name="new_password2", length=30, maxlength=30, is_required=True),
     117            oldforms.PasswordField(field_name="new_password2", length=30, max_length=30, is_required=True),
    118118        )
    119119
    120120    def isValidOldPassword(self, new_data, all_data):
     
    132132    def __init__(self, user):
    133133        self.user = user
    134134        self.fields = (
    135             oldforms.PasswordField(field_name='password1', length=30, maxlength=60, is_required=True),
    136             oldforms.PasswordField(field_name='password2', length=30, maxlength=60, is_required=True,
     135            oldforms.PasswordField(field_name='password1', length=30, max_length=60, is_required=True),
     136            oldforms.PasswordField(field_name='password2', length=30, max_length=60, is_required=True,
    137137                validator_list=[validators.AlwaysMatchesOtherField('password1', _("The two password fields didn't match."))]),
    138138        )
    139139
  • django/contrib/sessions/models.py

     
    4848    the sessions documentation that is shipped with Django (also available
    4949    on the Django website).
    5050    """
    51     session_key = models.CharField(_('session key'), maxlength=40, primary_key=True)
     51    session_key = models.CharField(_('session key'), max_length=40, primary_key=True)
    5252    session_data = models.TextField(_('session data'))
    5353    expire_date = models.DateTimeField(_('expire date'))
    5454    objects = SessionManager()
  • django/contrib/flatpages/models.py

     
    44from django.utils.translation import gettext_lazy as _
    55
    66class FlatPage(models.Model):
    7     url = models.CharField(_('URL'), maxlength=100, validator_list=[validators.isAlphaNumericURL],
     7    url = models.CharField(_('URL'), max_length=100, validator_list=[validators.isAlphaNumericURL],
    88        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)
    1010    content = models.TextField(_('content'))
    1111    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,
    1313        help_text=_("Example: 'flatpages/contact_page.html'. If this isn't provided, the system will use 'flatpages/default.html'."))
    1414    registration_required = models.BooleanField(_('registration required'), help_text=_("If this is checked, only logged-in users will be able to view the page."))
    1515    sites = models.ManyToManyField(Site)
  • django/newforms/fields.py

     
    102102
    103103    def widget_attrs(self, widget):
    104104        if self.max_length is not None and isinstance(widget, (TextInput, PasswordInput)):
     105            # The HTML attribute is maxlength, not max_length.
    105106            return {'maxlength': str(self.max_length)}
    106107
    107108class IntegerField(Field):
  • tests/modeltests/basic/models.py

     
    77from django.db import models
    88
    99class Article(models.Model):
    10     headline = models.CharField(maxlength=100, default='Default headline')
     10    headline = models.CharField(max_length=100, default='Default headline')
    1111    pub_date = models.DateTimeField()
    1212
    1313    class Meta:
  • tests/modeltests/m2m_recursive/models.py

     
    1515from django.db import models
    1616
    1717class Person(models.Model):
    18     name = models.CharField(maxlength=20)
     18    name = models.CharField(max_length=20)
    1919    friends = models.ManyToManyField('self')
    2020    idols = models.ManyToManyField('self', symmetrical=False, related_name='stalkers')
    2121
  • tests/modeltests/one_to_one/models.py

     
    99from django.db import models
    1010
    1111class Place(models.Model):
    12     name = models.CharField(maxlength=50)
    13     address = models.CharField(maxlength=80)
     12    name = models.CharField(max_length=50)
     13    address = models.CharField(max_length=80)
    1414
    1515    def __str__(self):
    1616        return "%s the place" % self.name
     
    2525
    2626class Waiter(models.Model):
    2727    restaurant = models.ForeignKey(Restaurant)
    28     name = models.CharField(maxlength=50)
     28    name = models.CharField(max_length=50)
    2929
    3030    def __str__(self):
    3131        return "%s the waiter at %s" % (self.name, self.restaurant)
    3232
    3333class ManualPrimaryKey(models.Model):
    34     primary_key = models.CharField(maxlength=10, primary_key=True)
    35     name = models.CharField(maxlength = 50)
     34    primary_key = models.CharField(max_length=10, primary_key=True)
     35    name = models.CharField(max_length = 50)
    3636
    3737class RelatedModel(models.Model):
    3838    link = models.OneToOneField(ManualPrimaryKey)
    39     name = models.CharField(maxlength = 50)
     39    name = models.CharField(max_length = 50)
    4040
    4141__test__ = {'API_TESTS':"""
    4242# Create a couple of Places.
  • tests/modeltests/m2o_recursive/models.py

     
    1313from django.db import models
    1414
    1515class Category(models.Model):
    16     name = models.CharField(maxlength=20)
     16    name = models.CharField(max_length=20)
    1717    parent = models.ForeignKey('self', null=True, related_name='child_set')
    1818
    1919    def __str__(self):
  • tests/modeltests/custom_managers/models.py

     
    1818        return self.filter(fun=True)
    1919
    2020class Person(models.Model):
    21     first_name = models.CharField(maxlength=30)
    22     last_name = models.CharField(maxlength=30)
     21    first_name = models.CharField(max_length=30)
     22    last_name = models.CharField(max_length=30)
    2323    fun = models.BooleanField()
    2424    objects = PersonManager()
    2525
     
    3333        return super(PublishedBookManager, self).get_query_set().filter(is_published=True)
    3434
    3535class Book(models.Model):
    36     title = models.CharField(maxlength=50)
    37     author = models.CharField(maxlength=30)
     36    title = models.CharField(max_length=50)
     37    author = models.CharField(max_length=30)
    3838    is_published = models.BooleanField()
    3939    published_objects = PublishedBookManager()
    4040    authors = models.ManyToManyField(Person, related_name='books')
     
    4949        return super(FastCarManager, self).get_query_set().filter(top_speed__gt=150)
    5050
    5151class Car(models.Model):
    52     name = models.CharField(maxlength=10)
     52    name = models.CharField(max_length=10)
    5353    mileage = models.IntegerField()
    5454    top_speed = models.IntegerField(help_text="In miles per hour.")
    5555    cars = models.Manager()
  • tests/modeltests/invalid_models/models.py

     
    1010    charfield = models.CharField()
    1111    floatfield = models.FloatField()
    1212    filefield = models.FileField()
    13     prepopulate = models.CharField(maxlength=10, prepopulate_from='bad')
    14     choices = models.CharField(maxlength=10, choices='bad')
    15     choices2 = models.CharField(maxlength=10, choices=[(1,2,3),(1,2,3)])
    16     index = models.CharField(maxlength=10, db_index='bad')
     13    prepopulate = models.CharField(max_length=10, prepopulate_from='bad')
     14    choices = models.CharField(max_length=10, choices='bad')
     15    choices2 = models.CharField(max_length=10, choices=[(1,2,3),(1,2,3)])
     16    index = models.CharField(max_length=10, db_index='bad')
    1717
    1818class Target(models.Model):
    19     tgt_safe = models.CharField(maxlength=10)
    20     clash1 = models.CharField(maxlength=10)
    21     clash2 = models.CharField(maxlength=10)
     19    tgt_safe = models.CharField(max_length=10)
     20    clash1 = models.CharField(max_length=10)
     21    clash2 = models.CharField(max_length=10)
    2222
    23     clash1_set = models.CharField(maxlength=10)
     23    clash1_set = models.CharField(max_length=10)
    2424
    2525class Clash1(models.Model):
    26     src_safe = models.CharField(maxlength=10, core=True)
     26    src_safe = models.CharField(max_length=10, core=True)
    2727
    2828    foreign = models.ForeignKey(Target)
    2929    m2m = models.ManyToManyField(Target)
    3030
    3131class Clash2(models.Model):
    32     src_safe = models.CharField(maxlength=10, core=True)
     32    src_safe = models.CharField(max_length=10, core=True)
    3333
    3434    foreign_1 = models.ForeignKey(Target, related_name='id')
    3535    foreign_2 = models.ForeignKey(Target, related_name='src_safe')
     
    3838    m2m_2 = models.ManyToManyField(Target, related_name='src_safe')
    3939
    4040class Target2(models.Model):
    41     clash3 = models.CharField(maxlength=10)
     41    clash3 = models.CharField(max_length=10)
    4242    foreign_tgt = models.ForeignKey(Target)
    4343    clashforeign_set = models.ForeignKey(Target)
    4444
     
    4646    clashm2m_set = models.ManyToManyField(Target)
    4747
    4848class Clash3(models.Model):
    49     src_safe = models.CharField(maxlength=10, core=True)
     49    src_safe = models.CharField(max_length=10, core=True)
    5050   
    5151    foreign_1 = models.ForeignKey(Target2, related_name='foreign_tgt')
    5252    foreign_2 = models.ForeignKey(Target2, related_name='m2m_tgt')
     
    6161    m2m = models.ManyToManyField(Target2)
    6262
    6363class SelfClashForeign(models.Model):
    64     src_safe = models.CharField(maxlength=10, core=True)
    65     selfclashforeign = models.CharField(maxlength=10)
     64    src_safe = models.CharField(max_length=10, core=True)
     65    selfclashforeign = models.CharField(max_length=10)
    6666
    6767    selfclashforeign_set = models.ForeignKey("SelfClashForeign")
    6868    foreign_1 = models.ForeignKey("SelfClashForeign", related_name='id')
    6969    foreign_2 = models.ForeignKey("SelfClashForeign", related_name='src_safe')
    7070
    7171class ValidM2M(models.Model):
    72     src_safe = models.CharField(maxlength=10)
    73     validm2m = models.CharField(maxlength=10)
     72    src_safe = models.CharField(max_length=10)
     73    validm2m = models.CharField(max_length=10)
    7474
    7575    # M2M fields are symmetrical by default. Symmetrical M2M fields
    7676    # on self don't require a related accessor, so many potential
     
    8484    m2m_4 = models.ManyToManyField('self')
    8585
    8686class SelfClashM2M(models.Model):
    87     src_safe = models.CharField(maxlength=10)
    88     selfclashm2m = models.CharField(maxlength=10)
     87    src_safe = models.CharField(max_length=10)
     88    selfclashm2m = models.CharField(max_length=10)
    8989
    9090    # Non-symmetrical M2M fields _do_ have related accessors, so
    9191    # there is potential for clashes.
     
    9797    m2m_3 = models.ManyToManyField('self', symmetrical=False)
    9898    m2m_4 = models.ManyToManyField('self', symmetrical=False)
    9999
    100 model_errors = """invalid_models.fielderrors: "charfield": CharFields require a "maxlength" attribute.
     100model_errors = """invalid_models.fielderrors: "charfield": CharFields require a "max_length" attribute.
    101101invalid_models.fielderrors: "floatfield": FloatFields require a "decimal_places" attribute.
    102102invalid_models.fielderrors: "floatfield": FloatFields require a "max_digits" attribute.
    103103invalid_models.fielderrors: "filefield": FileFields require an "upload_to" attribute.
  • tests/modeltests/many_to_many/models.py

     
    1010from django.db import models
    1111
    1212class Publication(models.Model):
    13     title = models.CharField(maxlength=30)
     13    title = models.CharField(max_length=30)
    1414
    1515    def __str__(self):
    1616        return self.title
     
    1919        ordering = ('title',)
    2020
    2121class Article(models.Model):
    22     headline = models.CharField(maxlength=100)
     22    headline = models.CharField(max_length=100)
    2323    publications = models.ManyToManyField(Publication)
    2424
    2525    def __str__(self):
  • tests/modeltests/m2m_and_m2o/models.py

     
    77from django.db import models
    88
    99class User(models.Model):
    10     username = models.CharField(maxlength=20)
     10    username = models.CharField(max_length=20)
    1111
    1212class Issue(models.Model):
    1313    num = models.IntegerField()
  • tests/modeltests/validation/models.py

     
    1212
    1313class Person(models.Model):
    1414    is_child = models.BooleanField()
    15     name = models.CharField(maxlength=20)
     15    name = models.CharField(max_length=20)
    1616    birthdate = models.DateField()
    1717    favorite_moment = models.DateTimeField()
    1818    email = models.EmailField()
  • tests/modeltests/or_lookups/models.py

     
    1414from django.db import models
    1515
    1616class Article(models.Model):
    17     headline = models.CharField(maxlength=50)
     17    headline = models.CharField(max_length=50)
    1818    pub_date = models.DateTimeField()
    1919
    2020    class Meta:
  • tests/modeltests/mutually_referential/models.py

     
    77from django.db.models import *
    88
    99class Parent(Model):
    10     name = CharField(maxlength=100, core=True)
     10    name = CharField(max_length=100, core=True)
    1111    bestchild = ForeignKey("Child", null=True, related_name="favoured_by")
    1212
    1313class Child(Model):
    14     name = CharField(maxlength=100)
     14    name = CharField(max_length=100)
    1515    parent = ForeignKey(Parent)
    1616
    1717__test__ = {'API_TESTS':"""
  • tests/modeltests/custom_methods/models.py

     
    88import datetime
    99
    1010class Article(models.Model):
    11     headline = models.CharField(maxlength=100)
     11    headline = models.CharField(max_length=100)
    1212    pub_date = models.DateField()
    1313
    1414    def __str__(self):
  • tests/modeltests/many_to_one_null/models.py

     
    88from django.db import models
    99
    1010class Reporter(models.Model):
    11     name = models.CharField(maxlength=30)
     11    name = models.CharField(max_length=30)
    1212
    1313    def __str__(self):
    1414        return self.name
    1515
    1616class Article(models.Model):
    17     headline = models.CharField(maxlength=100)
     17    headline = models.CharField(max_length=100)
    1818    reporter = models.ForeignKey(Reporter, null=True)
    1919
    2020    class Meta:
  • tests/modeltests/get_or_create/models.py

     
    88from django.db import models
    99
    1010class Person(models.Model):
    11     first_name = models.CharField(maxlength=100)
    12     last_name = models.CharField(maxlength=100)
     11    first_name = models.CharField(max_length=100)
     12    last_name = models.CharField(max_length=100)
    1313    birthday = models.DateField()
    1414
    1515    def __str__(self):
  • tests/modeltests/custom_pk/models.py

     
    88from django.db import models
    99
    1010class Employee(models.Model):
    11     employee_code = models.CharField(maxlength=10, primary_key=True,
     11    employee_code = models.CharField(max_length=10, primary_key=True,
    1212            db_column = 'code')
    13     first_name = models.CharField(maxlength=20)
    14     last_name = models.CharField(maxlength=20)
     13    first_name = models.CharField(max_length=20)
     14    last_name = models.CharField(max_length=20)
    1515    class Meta:
    1616        ordering = ('last_name', 'first_name')
    1717
     
    1919        return "%s %s" % (self.first_name, self.last_name)
    2020
    2121class Business(models.Model):
    22     name = models.CharField(maxlength=20, primary_key=True)
     22    name = models.CharField(max_length=20, primary_key=True)
    2323    employees = models.ManyToManyField(Employee)
    2424    class Meta:
    2525        verbose_name_plural = 'businesses'
  • tests/modeltests/reverse_lookup/models.py

     
    77from django.db import models
    88
    99class User(models.Model):
    10     name = models.CharField(maxlength=200)
     10    name = models.CharField(max_length=200)
    1111
    1212    def __str__(self):
    1313        return self.name
    1414
    1515class Poll(models.Model):
    16     question = models.CharField(maxlength=200)
     16    question = models.CharField(max_length=200)
    1717    creator = models.ForeignKey(User)
    1818
    1919    def __str__(self):
    2020        return self.question
    2121
    2222class Choice(models.Model):
    23     name = models.CharField(maxlength=100)
     23    name = models.CharField(max_length=100)
    2424    poll = models.ForeignKey(Poll, related_name="poll_choice")
    2525    related_poll = models.ForeignKey(Poll, related_name="related_choice")
    2626
  • tests/modeltests/m2o_recursive2/models.py

     
    1010from django.db import models
    1111
    1212class Person(models.Model):
    13     full_name = models.CharField(maxlength=20)
     13    full_name = models.CharField(max_length=20)
    1414    mother = models.ForeignKey('self', null=True, related_name='mothers_child_set')
    1515    father = models.ForeignKey('self', null=True, related_name='fathers_child_set')
    1616
  • tests/modeltests/m2m_multiple/models.py

     
    1010from django.db import models
    1111
    1212class Category(models.Model):
    13     name = models.CharField(maxlength=20)
     13    name = models.CharField(max_length=20)
    1414    class Meta:
    1515       ordering = ('name',)
    1616
     
    1818        return self.name
    1919
    2020class Article(models.Model):
    21     headline = models.CharField(maxlength=50)
     21    headline = models.CharField(max_length=50)
    2222    pub_date = models.DateTimeField()
    2323    primary_categories = models.ManyToManyField(Category, related_name='primary_article_set')
    2424    secondary_categories = models.ManyToManyField(Category, related_name='secondary_article_set')
  • tests/modeltests/m2m_intermediary/models.py

     
    1313from django.db import models
    1414
    1515class Reporter(models.Model):
    16     first_name = models.CharField(maxlength=30)
    17     last_name = models.CharField(maxlength=30)
     16    first_name = models.CharField(max_length=30)
     17    last_name = models.CharField(max_length=30)
    1818
    1919    def __str__(self):
    2020        return "%s %s" % (self.first_name, self.last_name)
    2121
    2222class Article(models.Model):
    23     headline = models.CharField(maxlength=100)
     23    headline = models.CharField(max_length=100)
    2424    pub_date = models.DateField()
    2525
    2626    def __str__(self):
     
    2929class Writer(models.Model):
    3030    reporter = models.ForeignKey(Reporter)
    3131    article = models.ForeignKey(Article)
    32     position = models.CharField(maxlength=100)
     32    position = models.CharField(max_length=100)
    3333
    3434    def __str__(self):
    3535        return '%s (%s)' % (self.reporter, self.position)
  • tests/modeltests/str/models.py

     
    1111from django.db import models
    1212
    1313class Article(models.Model):
    14     headline = models.CharField(maxlength=100)
     14    headline = models.CharField(max_length=100)
    1515    pub_date = models.DateTimeField()
    1616
    1717    def __str__(self):
  • tests/modeltests/transactions/models.py

     
    1010from django.db import models
    1111
    1212class Reporter(models.Model):
    13     first_name = models.CharField(maxlength=30)
    14     last_name = models.CharField(maxlength=30)
     13    first_name = models.CharField(max_length=30)
     14    last_name = models.CharField(max_length=30)
    1515    email = models.EmailField()
    1616
    1717    def __str__(self):
  • tests/modeltests/model_inheritance/models.py

     
    77from django.db import models
    88
    99class Place(models.Model):
    10     name = models.CharField(maxlength=50)
    11     address = models.CharField(maxlength=80)
     10    name = models.CharField(max_length=50)
     11    address = models.CharField(max_length=80)
    1212
    1313    def __str__(self):
    1414        return "%s the place" % self.name
  • tests/modeltests/lookup/models.py

     
    77from django.db import models
    88
    99class Article(models.Model):
    10     headline = models.CharField(maxlength=100)
     10    headline = models.CharField(max_length=100)
    1111    pub_date = models.DateTimeField()
    1212    class Meta:
    1313        ordering = ('-pub_date', 'headline')
  • tests/modeltests/choices/models.py

     
    1717)
    1818
    1919class Person(models.Model):
    20     name = models.CharField(maxlength=20)
    21     gender = models.CharField(maxlength=1, choices=GENDER_CHOICES)
     20    name = models.CharField(max_length=20)
     21    gender = models.CharField(max_length=1, choices=GENDER_CHOICES)
    2222
    2323    def __str__(self):
    2424        return self.name
  • tests/modeltests/save_delete_hooks/models.py

     
    88from django.db import models
    99
    1010class Person(models.Model):
    11     first_name = models.CharField(maxlength=20)
    12     last_name = models.CharField(maxlength=20)
     11    first_name = models.CharField(max_length=20)
     12    last_name = models.CharField(max_length=20)
    1313
    1414    def __str__(self):
    1515        return "%s %s" % (self.first_name, self.last_name)
  • tests/modeltests/pagination/models.py

     
    99from django.db import models
    1010
    1111class Article(models.Model):
    12     headline = models.CharField(maxlength=100, default='Default headline')
     12    headline = models.CharField(max_length=100, default='Default headline')
    1313    pub_date = models.DateTimeField()
    1414
    1515    def __str__(self):
  • tests/modeltests/get_latest/models.py

     
    1111from django.db import models
    1212
    1313class Article(models.Model):
    14     headline = models.CharField(maxlength=100)
     14    headline = models.CharField(max_length=100)
    1515    pub_date = models.DateField()
    1616    expire_date = models.DateField()
    1717    class Meta:
     
    2121        return self.headline
    2222
    2323class Person(models.Model):
    24     name = models.CharField(maxlength=30)
     24    name = models.CharField(max_length=30)
    2525    birthday = models.DateField()
    2626
    2727    # Note that this model doesn't have "get_latest_by" set.
  • tests/modeltests/properties/models.py

     
    77from django.db import models
    88
    99class Person(models.Model):
    10     first_name = models.CharField(maxlength=30)
    11     last_name = models.CharField(maxlength=30)
     10    first_name = models.CharField(max_length=30)
     11    last_name = models.CharField(max_length=30)
    1212
    1313    def _get_full_name(self):
    1414        return "%s %s" % (self.first_name, self.last_name)
  • tests/modeltests/generic_relations/models.py

     
    2727        return self.tag
    2828
    2929class Animal(models.Model):
    30     common_name = models.CharField(maxlength=150)
    31     latin_name = models.CharField(maxlength=150)
     30    common_name = models.CharField(max_length=150)
     31    latin_name = models.CharField(max_length=150)
    3232   
    3333    tags = models.GenericRelation(TaggedItem)
    3434
     
    3636        return self.common_name
    3737       
    3838class Vegetable(models.Model):
    39     name = models.CharField(maxlength=150)
     39    name = models.CharField(max_length=150)
    4040    is_yucky = models.BooleanField(default=True)
    4141   
    4242    tags = models.GenericRelation(TaggedItem)
     
    4545        return self.name
    4646   
    4747class Mineral(models.Model):
    48     name = models.CharField(maxlength=150)
     48    name = models.CharField(max_length=150)
    4949    hardness = models.PositiveSmallIntegerField()
    5050   
    5151    # note the lack of an explicit GenericRelation here...
  • tests/modeltests/serializers/models.py

     
    88from django.db import models
    99
    1010class Category(models.Model):
    11     name = models.CharField(maxlength=20)
     11    name = models.CharField(max_length=20)
    1212
    1313    class Meta:
    1414       ordering = ('name',)
     
    1717        return self.name
    1818
    1919class Author(models.Model):
    20     name = models.CharField(maxlength=20)
     20    name = models.CharField(max_length=20)
    2121
    2222    class Meta:
    2323        ordering = ('name',)
     
    2727
    2828class Article(models.Model):
    2929    author = models.ForeignKey(Author)
    30     headline = models.CharField(maxlength=50)
     30    headline = models.CharField(max_length=50)
    3131    pub_date = models.DateTimeField()
    3232    categories = models.ManyToManyField(Category)
    3333
  • tests/modeltests/get_object_or_404/models.py

     
    1515from django.shortcuts import get_object_or_404, get_list_or_404
    1616
    1717class Author(models.Model):
    18     name = models.CharField(maxlength=50)
     18    name = models.CharField(max_length=50)
    1919   
    2020    def __str__(self):
    2121        return self.name
     
    2626
    2727class Article(models.Model):
    2828    authors = models.ManyToManyField(Author)
    29     title = models.CharField(maxlength=50)
     29    title = models.CharField(max_length=50)
    3030    objects = models.Manager()
    3131    by_a_sir = ArticleManager()
    3232   
  • tests/modeltests/reserved_names/models.py

     
    1010from django.db import models
    1111
    1212class Thing(models.Model):
    13     when = models.CharField(maxlength=1, primary_key=True)
    14     join = models.CharField(maxlength=1)
    15     like = models.CharField(maxlength=1)
    16     drop = models.CharField(maxlength=1)
    17     alter = models.CharField(maxlength=1)
    18     having = models.CharField(maxlength=1)
    19     where = models.DateField(maxlength=1)
    20     has_hyphen = models.CharField(maxlength=1, db_column='has-hyphen')
     13    when = models.CharField(max_length=1, primary_key=True)
     14    join = models.CharField(max_length=1)
     15    like = models.CharField(max_length=1)
     16    drop = models.CharField(max_length=1)
     17    alter = models.CharField(max_length=1)
     18    having = models.CharField(max_length=1)
     19    where = models.DateField(max_length=1)
     20    has_hyphen = models.CharField(max_length=1, db_column='has-hyphen')
    2121    class Meta:
    2222       db_table = 'select'
    2323
  • tests/modeltests/model_forms/models.py

     
    2525from django.db import models
    2626
    2727class Category(models.Model):
    28     name = models.CharField(maxlength=20)
    29     url = models.CharField('The URL', maxlength=40)
     28    name = models.CharField(max_length=20)
     29    url = models.CharField('The URL', max_length=40)
    3030
    3131    def __str__(self):
    3232        return self.name
    3333
    3434class Writer(models.Model):
    35     name = models.CharField(maxlength=50)
     35    name = models.CharField(max_length=50)
    3636
    3737    def __str__(self):
    3838        return self.name
    3939
    4040class Article(models.Model):
    41     headline = models.CharField(maxlength=50)
     41    headline = models.CharField(max_length=50)
    4242    pub_date = models.DateField()
    4343    writer = models.ForeignKey(Writer)
    4444    article = models.TextField()
     
    5757>>> CategoryForm = form_for_model(Category)
    5858>>> f = CategoryForm()
    5959>>> print f
    60 <tr><th><label for="id_name">Name:</label></th><td><input id="id_name" type="text" name="name" maxlength="20" /></td></tr>
    61 <tr><th><label for="id_url">The URL:</label></th><td><input id="id_url" type="text" name="url" maxlength="40" /></td></tr>
     60<tr><th><label for="id_name">Name:</label></th><td><input id="id_name" type="text" name="name" max_length="20" /></td></tr>
     61<tr><th><label for="id_url">The URL:</label></th><td><input id="id_url" type="text" name="url" max_length="40" /></td></tr>
    6262>>> print f.as_ul()
    63 <li><label for="id_name">Name:</label> <input id="id_name" type="text" name="name" maxlength="20" /></li>
    64 <li><label for="id_url">The URL:</label> <input id="id_url" type="text" name="url" maxlength="40" /></li>
     63<li><label for="id_name">Name:</label> <input id="id_name" type="text" name="name" max_length="20" /></li>
     64<li><label for="id_url">The URL:</label> <input id="id_url" type="text" name="url" max_length="40" /></li>
    6565>>> print f['name']
    66 <input id="id_name" type="text" name="name" maxlength="20" />
     66<input id="id_name" type="text" name="name" max_length="20" />
    6767
    6868>>> f = CategoryForm(auto_id=False)
    6969>>> print f.as_ul()
    70 <li>Name: <input type="text" name="name" maxlength="20" /></li>
    71 <li>The URL: <input type="text" name="url" maxlength="40" /></li>
     70<li>Name: <input type="text" name="name" max_length="20" /></li>
     71<li>The URL: <input type="text" name="url" max_length="40" /></li>
    7272
    7373>>> f = CategoryForm({'name': 'Entertainment', 'url': 'entertainment'})
    7474>>> f.is_valid()
     
    138138>>> ArticleForm = form_for_model(Article)
    139139>>> f = ArticleForm(auto_id=False)
    140140>>> print f
    141 <tr><th>Headline:</th><td><input type="text" name="headline" maxlength="50" /></td></tr>
     141<tr><th>Headline:</th><td><input type="text" name="headline" max_length="50" /></td></tr>
    142142<tr><th>Pub date:</th><td><input type="text" name="pub_date" /></td></tr>
    143143<tr><th>Writer:</th><td><select name="writer">
    144144<option value="" selected="selected">---------</option>
     
    169169>>> RoykoForm = form_for_instance(w)
    170170>>> f = RoykoForm(auto_id=False)
    171171>>> print f
    172 <tr><th>Name:</th><td><input type="text" name="name" value="Mike Royko" maxlength="50" /></td></tr>
     172<tr><th>Name:</th><td><input type="text" name="name" value="Mike Royko" max_length="50" /></td></tr>
    173173
    174174>>> art = Article(headline='Test article', pub_date=datetime.date(1988, 1, 4), writer=w, article='Hello.')
    175175>>> art.save()
     
    178178>>> TestArticleForm = form_for_instance(art)
    179179>>> f = TestArticleForm(auto_id=False)
    180180>>> print f.as_ul()
    181 <li>Headline: <input type="text" name="headline" value="Test article" maxlength="50" /></li>
     181<li>Headline: <input type="text" name="headline" value="Test article" max_length="50" /></li>
    182182<li>Pub date: <input type="text" name="pub_date" value="1988-01-04" /></li>
    183183<li>Writer: <select name="writer">
    184184<option value="">---------</option>
     
    210210>>> TestArticleForm = form_for_instance(new_art)
    211211>>> f = TestArticleForm(auto_id=False)
    212212>>> print f.as_ul()
    213 <li>Headline: <input type="text" name="headline" value="New headline" maxlength="50" /></li>
     213<li>Headline: <input type="text" name="headline" value="New headline" max_length="50" /></li>
    214214<li>Pub date: <input type="text" name="pub_date" value="1988-01-04" /></li>
    215215<li>Writer: <select name="writer">
    216216<option value="">---------</option>
  • tests/modeltests/many_to_one/models.py

     
    77from django.db import models
    88
    99class Reporter(models.Model):
    10     first_name = models.CharField(maxlength=30)
    11     last_name = models.CharField(maxlength=30)
     10    first_name = models.CharField(max_length=30)
     11    last_name = models.CharField(max_length=30)
    1212    email = models.EmailField()
    1313
    1414    def __str__(self):
    1515        return "%s %s" % (self.first_name, self.last_name)
    1616
    1717class Article(models.Model):
    18     headline = models.CharField(maxlength=100)
     18    headline = models.CharField(max_length=100)
    1919    pub_date = models.DateField()
    2020    reporter = models.ForeignKey(Reporter)
    2121
  • tests/modeltests/ordering/models.py

     
    1616from django.db import models
    1717
    1818class Article(models.Model):
    19     headline = models.CharField(maxlength=100)
     19    headline = models.CharField(max_length=100)
    2020    pub_date = models.DateTimeField()
    2121    class Meta:
    2222        ordering = ('-pub_date', 'headline')
  • tests/modeltests/custom_columns/models.py

     
    99from django.db import models
    1010
    1111class Person(models.Model):
    12     first_name = models.CharField(maxlength=30, db_column='firstname')
    13     last_name = models.CharField(maxlength=30, db_column='last')
     12    first_name = models.CharField(max_length=30, db_column='firstname')
     13    last_name = models.CharField(max_length=30, db_column='last')
    1414
    1515    def __str__(self):
    1616        return '%s %s' % (self.first_name, self.last_name)
  • tests/modeltests/field_defaults/models.py

     
    1313from datetime import datetime
    1414
    1515class Article(models.Model):
    16     headline = models.CharField(maxlength=100, default='Default headline')
     16    headline = models.CharField(max_length=100, default='Default headline')
    1717    pub_date = models.DateTimeField(default=datetime.now)
    1818
    1919    def __str__(self):
  • tests/modeltests/manipulators/models.py

     
    77from django.db import models
    88
    99class Musician(models.Model):
    10     first_name = models.CharField(maxlength=30)
    11     last_name = models.CharField(maxlength=30)
     10    first_name = models.CharField(max_length=30)
     11    last_name = models.CharField(max_length=30)
    1212
    1313    def __str__(self):
    1414        return "%s %s" % (self.first_name, self.last_name)
    1515
    1616class Album(models.Model):
    17     name = models.CharField(maxlength=100)
     17    name = models.CharField(max_length=100)
    1818    musician = models.ForeignKey(Musician)
    1919    release_date = models.DateField(blank=True, null=True)
    2020
  • tests/regressiontests/string_lookup/models.py

     
    11from django.db import models
    22
    33class Foo(models.Model):
    4     name = models.CharField(maxlength=50)
     4    name = models.CharField(max_length=50)
    55
    66    def __str__(self):
    77        return "Foo %s" % self.name
    88
    99class Bar(models.Model):
    10     name = models.CharField(maxlength=50)
     10    name = models.CharField(max_length=50)
    1111    normal = models.ForeignKey(Foo, related_name='normal_foo')
    1212    fwd = models.ForeignKey("Whiz")
    1313    back = models.ForeignKey("Foo")
     
    1616        return "Bar %s" % self.place.name
    1717
    1818class Whiz(models.Model):
    19     name = models.CharField(maxlength = 50)
     19    name = models.CharField(max_length = 50)
    2020
    2121    def __str__(self):
    2222        return "Whiz %s" % self.name
    2323
    2424class Child(models.Model):
    2525    parent = models.OneToOneField('Base')
    26     name = models.CharField(maxlength = 50)
     26    name = models.CharField(max_length = 50)
    2727
    2828    def __str__(self):
    2929        return "Child %s" % self.name
    3030   
    3131class Base(models.Model):
    32     name = models.CharField(maxlength = 50)
     32    name = models.CharField(max_length = 50)
    3333
    3434    def __str__(self):
    3535        return "Base %s" % self.name
  • tests/regressiontests/initial_sql_regress/models.py

     
    55from django.db import models
    66
    77class Simple(models.Model):
    8     name = models.CharField(maxlength = 50)
     8    name = models.CharField(max_length = 50)
    99
    1010__test__ = {'API_TESTS':""}
    1111
  • tests/regressiontests/null_queries/models.py

     
    11from django.db import models
    22
    33class Poll(models.Model):
    4     question = models.CharField(maxlength=200)
     4    question = models.CharField(max_length=200)
    55
    66    def __str__(self):
    77        return "Q: %s " % self.question
    88
    99class Choice(models.Model):
    1010    poll = models.ForeignKey(Poll)
    11     choice = models.CharField(maxlength=200)
     11    choice = models.CharField(max_length=200)
    1212
    1313    def __str__(self):
    1414        return "Choice: %s in poll %s" % (self.choice, self.poll)
  • tests/regressiontests/invalid_admin_options/models.py

     
    1212##This should fail gracefully but is causing a metaclass error
    1313#class BadAdminOption(models.Model):
    1414#    "Test nonexistent admin option"
    15 #    name = models.CharField(maxlength=30)
     15#    name = models.CharField(max_length=30)
    1616#   
    1717#    class Admin:
    1818#        nonexistent = 'option'
     
    2222       
    2323class ListDisplayBadOne(models.Model):
    2424    "Test list_display, list_display must be a list or tuple"
    25     first_name = models.CharField(maxlength=30)
     25    first_name = models.CharField(max_length=30)
    2626
    2727    class Admin:
    2828        list_display = 'first_name'
     
    3232
    3333class ListDisplayBadTwo(models.Model):
    3434    "Test list_display, list_display items must be attributes, methods or properties."
    35     first_name = models.CharField(maxlength=30)
     35    first_name = models.CharField(max_length=30)
    3636
    3737    class Admin:
    3838        list_display = ['first_name','nonexistent']
     
    4141"""       
    4242class ListDisplayBadThree(models.Model):
    4343    "Test list_display, list_display items can not be a ManyToManyField."
    44     first_name = models.CharField(maxlength=30)
     44    first_name = models.CharField(max_length=30)
    4545    nick_names = models.ManyToManyField('ListDisplayGood')
    4646
    4747    class Admin:
     
    5252     
    5353class ListDisplayGood(models.Model):
    5454    "Test list_display, Admin list_display can be a attribute, method or property."
    55     first_name = models.CharField(maxlength=30)
     55    first_name = models.CharField(max_length=30)
    5656   
    5757    def _last_name(self):
    5858        return self.first_name
     
    6666       
    6767class ListDisplayLinksBadOne(models.Model):
    6868    "Test list_display_links, item must be included in list_display."
    69     first_name = models.CharField(maxlength=30)
    70     last_name = models.CharField(maxlength=30)
     69    first_name = models.CharField(max_length=30)
     70    last_name = models.CharField(max_length=30)
    7171   
    7272    class Admin:
    7373        list_display = ['last_name']
     
    7878
    7979class ListDisplayLinksBadTwo(models.Model):
    8080    "Test list_display_links, must be a list or tuple."
    81     first_name = models.CharField(maxlength=30)
    82     last_name = models.CharField(maxlength=30)
     81    first_name = models.CharField(max_length=30)
     82    last_name = models.CharField(max_length=30)
    8383   
    8484    class Admin:
    8585        list_display = ['first_name','last_name']
     
    9292## This is failing but the validation which should fail is not.
    9393#class ListDisplayLinksBadThree(models.Model):
    9494#    "Test list_display_links, must define list_display to use list_display_links."
    95 #    first_name = models.CharField(maxlength=30)
    96 #    last_name = models.CharField(maxlength=30)
     95#    first_name = models.CharField(max_length=30)
     96#    last_name = models.CharField(max_length=30)
    9797#   
    9898#    class Admin:
    9999#        list_display_links = ('first_name',)
     
    103103       
    104104class ListDisplayLinksGood(models.Model):
    105105    "Test list_display_links, Admin list_display_list can be a attribute, method or property."
    106     first_name = models.CharField(maxlength=30)
     106    first_name = models.CharField(max_length=30)
    107107   
    108108    def _last_name(self):
    109109        return self.first_name
     
    118118
    119119class ListFilterBadOne(models.Model):
    120120    "Test list_filter, must be a list or tuple."
    121     first_name = models.CharField(maxlength=30)
     121    first_name = models.CharField(max_length=30)
    122122   
    123123    class Admin:
    124124        list_filter = 'first_name'     
     
    128128
    129129class ListFilterBadTwo(models.Model):
    130130    "Test list_filter, must be a field not a property or method."
    131     first_name = models.CharField(maxlength=30)
     131    first_name = models.CharField(max_length=30)
    132132   
    133133    def _last_name(self):
    134134        return self.first_name
     
    146146
    147147class DateHierarchyBadOne(models.Model):
    148148    "Test date_hierarchy, must be a date or datetime field."
    149     first_name = models.CharField(maxlength=30)
     149    first_name = models.CharField(max_length=30)
    150150    birth_day = models.DateField()
    151151   
    152152    class Admin:
     
    158158
    159159class DateHierarchyBadTwo(models.Model):
    160160    "Test date_hieracrhy, must be a field."
    161     first_name = models.CharField(maxlength=30)
     161    first_name = models.CharField(max_length=30)
    162162    birth_day = models.DateField()
    163163   
    164164    class Admin:
     
    169169
    170170class DateHierarchyGood(models.Model):
    171171    "Test date_hieracrhy, must be a field."
    172     first_name = models.CharField(maxlength=30)
     172    first_name = models.CharField(max_length=30)
    173173    birth_day = models.DateField()
    174174   
    175175    class Admin:
     
    177177     
    178178class SearchFieldsBadOne(models.Model):
    179179    "Test search_fields, must be a list or tuple."
    180     first_name = models.CharField(maxlength=30)
     180    first_name = models.CharField(max_length=30)
    181181   
    182182    class Admin:
    183183        search_fields = ('nonexistent')         
     
    188188     
    189189class SearchFieldsBadTwo(models.Model):
    190190    "Test search_fields, must be a field."
    191     first_name = models.CharField(maxlength=30)
     191    first_name = models.CharField(max_length=30)
    192192
    193193    def _last_name(self):
    194194        return self.first_name
     
    203203
    204204class SearchFieldsGood(models.Model):
    205205    "Test search_fields, must be a list or tuple."
    206     first_name = models.CharField(maxlength=30)
    207     last_name = models.CharField(maxlength=30)
     206    first_name = models.CharField(max_length=30)
     207    last_name = models.CharField(max_length=30)
    208208   
    209209    class Admin:
    210210        search_fields = ['first_name','last_name']
     
    212212
    213213class JsBadOne(models.Model):
    214214    "Test js, must be a list or tuple"
    215     name = models.CharField(maxlength=30)
     215    name = models.CharField(max_length=30)
    216216   
    217217    class Admin:
    218218        js = 'test.js'
     
    223223
    224224class SaveAsBad(models.Model):
    225225    "Test save_as, should be True or False"
    226     name = models.CharField(maxlength=30)
     226    name = models.CharField(max_length=30)
    227227   
    228228    class Admin:
    229229        save_as = 'not True or False'
     
    234234
    235235class SaveOnTopBad(models.Model):
    236236    "Test save_on_top, should be True or False"
    237     name = models.CharField(maxlength=30)
     237    name = models.CharField(max_length=30)
    238238   
    239239    class Admin:
    240240        save_on_top = 'not True or False'
     
    245245
    246246class ListSelectRelatedBad(models.Model):
    247247    "Test list_select_related, should be True or False"
    248     name = models.CharField(maxlength=30)
     248    name = models.CharField(max_length=30)
    249249   
    250250    class Admin:
    251251        list_select_related = 'not True or False'
     
    256256
    257257class ListPerPageBad(models.Model):
    258258    "Test list_per_page, should be a positive integer value."
    259     name = models.CharField(maxlength=30)
     259    name = models.CharField(max_length=30)
    260260   
    261261    class Admin:
    262262        list_per_page = 89.3
     
    267267
    268268class FieldsBadOne(models.Model):
    269269    "Test fields, should be a tuple"
    270     first_name = models.CharField(maxlength=30)
    271     last_name = models.CharField(maxlength=30)
     270    first_name = models.CharField(max_length=30)
     271    last_name = models.CharField(max_length=30)
    272272   
    273273    class Admin:
    274274        fields = 'not a tuple'
     
    279279
    280280class FieldsBadTwo(models.Model):
    281281    """Test fields, 'fields' dict option is required."""
    282     first_name = models.CharField(maxlength=30)
    283     last_name = models.CharField(maxlength=30)
     282    first_name = models.CharField(max_length=30)
     283    last_name = models.CharField(max_length=30)
    284284   
    285285    class Admin:
    286286        fields = ('Name', {'description': 'this fieldset needs fields'})
     
    291291
    292292class FieldsBadThree(models.Model):
    293293    """Test fields, 'classes' and 'description' are the only allowable extra dict options."""
    294     first_name = models.CharField(maxlength=30)
    295     last_name = models.CharField(maxlength=30)
     294    first_name = models.CharField(max_length=30)
     295    last_name = models.CharField(max_length=30)
    296296   
    297297    class Admin:
    298298        fields = ('Name', {'fields': ('first_name','last_name'),'badoption': 'verybadoption'})
     
    303303
    304304class FieldsGood(models.Model):
    305305    "Test fields, working example"
    306     first_name = models.CharField(maxlength=30)
    307     last_name = models.CharField(maxlength=30)
     306    first_name = models.CharField(max_length=30)
     307    last_name = models.CharField(max_length=30)
    308308    birth_day = models.DateField()
    309309   
    310310    class Admin:
     
    315315                 
    316316class OrderingBad(models.Model):
    317317    "Test ordering, must be a field."
    318     first_name = models.CharField(maxlength=30)
    319     last_name = models.CharField(maxlength=30)
     318    first_name = models.CharField(max_length=30)
     319    last_name = models.CharField(max_length=30)
    320320   
    321321    class Admin:
    322322        ordering = 'nonexistent'
     
    328328## TODO: Add a manager validator, this should fail gracefully.
    329329#class ManagerBad(models.Model):
    330330#    "Test manager, must be a manager object."
    331 #    first_name = models.CharField(maxlength=30)
     331#    first_name = models.CharField(max_length=30)
    332332#   
    333333#    class Admin:
    334334#        manager = 'nonexistent'
  • tests/regressiontests/one_to_one_regress/models.py

     
    11from django.db import models
    22
    33class Place(models.Model):
    4     name = models.CharField(maxlength=50)
    5     address = models.CharField(maxlength=80)
     4    name = models.CharField(max_length=50)
     5    address = models.CharField(max_length=80)
    66
    77    def __str__(self):
    88        return "%s the place" % self.name
     
    1616        return "%s the restaurant" % self.place.name
    1717
    1818class Favorites(models.Model):
    19     name = models.CharField(maxlength = 50)
     19    name = models.CharField(max_length = 50)
    2020    restaurants = models.ManyToManyField(Restaurant)
    2121
    2222    def __str__(self):
  • docs/tutorial01.txt

     
    233233    from django.db import models
    234234
    235235    class Poll(models.Model):
    236         question = models.CharField(maxlength=200)
     236        question = models.CharField(max_length=200)
    237237        pub_date = models.DateTimeField('date published')
    238238
    239239    class Choice(models.Model):
    240240        poll = models.ForeignKey(Poll)
    241         choice = models.CharField(maxlength=200)
     241        choice = models.CharField(max_length=200)
    242242        votes = models.IntegerField()
    243243
    244244The code is straightforward. Each model is represented by a class that
     
    261261machine-readable name will suffice as its human-readable name.
    262262
    263263Some ``Field`` classes have required elements. ``CharField``, for example,
    264 requires that you give it a ``maxlength``. That's used not only in the database
     264requires that you give it a ``max_length``. That's used not only in the database
    265265schema, but in validation, as we'll soon see.
    266266
    267267Finally, note a relationship is defined, using ``models.ForeignKey``. That tells
  • docs/tutorial02.txt

     
    240240
    241241Then change the other fields in ``Choice`` to give them ``core=True``::
    242242
    243     choice = models.CharField(maxlength=200, core=True)
     243    choice = models.CharField(max_length=200, core=True)
    244244    votes = models.IntegerField(core=True)
    245245
    246246This tells Django: "When you edit a Choice on the Poll admin page, the 'choice'
  • docs/db-api.txt

     
    1212a weblog application::
    1313
    1414    class Blog(models.Model):
    15         name = models.CharField(maxlength=100)
     15        name = models.CharField(max_length=100)
    1616        tagline = models.TextField()
    1717
    1818        def __str__(self):
    1919            return self.name
    2020
    2121    class Author(models.Model):
    22         name = models.CharField(maxlength=50)
     22        name = models.CharField(max_length=50)
    2323        email = models.URLField()
    2424
    2525        def __str__(self):
     
    2727
    2828    class Entry(models.Model):
    2929        blog = models.ForeignKey(Blog)
    30         headline = models.CharField(maxlength=255)
     30        headline = models.CharField(max_length=255)
    3131        body_text = models.TextField()
    3232        pub_date = models.DateTimeField()
    3333        authors = models.ManyToManyField(Author)
     
    16331633        ('F', 'Female'),
    16341634    )
    16351635    class Person(models.Model):
    1636         name = models.CharField(maxlength=20)
    1637         gender = models.CharField(maxlength=1, choices=GENDER_CHOICES)
     1636        name = models.CharField(max_length=20)
     1637        gender = models.CharField(max_length=1, choices=GENDER_CHOICES)
    16381638
    16391639...each ``Person`` instance will have a ``get_gender_display()`` method. Example::
    16401640
  • docs/overview.txt

     
    2525quick example::
    2626
    2727    class Reporter(models.Model):
    28         full_name = models.CharField(maxlength=70)
     28        full_name = models.CharField(max_length=70)
    2929
    3030        def __str__(self):
    3131            return self.full_name
    3232
    3333    class Article(models.Model):
    3434        pub_date = models.DateTimeField()
    35         headline = models.CharField(maxlength=200)
     35        headline = models.CharField(max_length=200)
    3636        article = models.TextField()
    3737        reporter = models.ForeignKey(Reporter)
    3838
     
    134134
    135135    class Article(models.Model):
    136136        pub_date = models.DateTimeField()
    137         headline = models.CharField(maxlength=200)
     137        headline = models.CharField(max_length=200)
    138138        article = models.TextField()
    139139        reporter = models.ForeignKey(Reporter)
    140140        class Admin: pass
  • docs/model-api.txt

     
    3333    from django.db import models
    3434
    3535    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)
    3838
    3939``first_name`` and ``last_name`` are *fields* of the model. Each field is
    4040specified as a class attribute, and each attribute maps to a database column.
     
    6969Example::
    7070
    7171    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)
    7575
    7676    class Album(models.Model):
    7777        artist = models.ForeignKey(Musician)
    78         name = models.CharField(maxlength=100)
     78        name = models.CharField(max_length=100)
    7979        release_date = models.DateField()
    8080        num_stars = models.IntegerField()
    8181
     
    142142
    143143The admin represents this as an ``<input type="text">`` (a single-line input).
    144144
    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
    147 and in Django's validation.
     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
     147and in Django's validation. 
    148148
     149Django veterans: Please note that the argument is no called ``max_length``, instead
     150of ``maxlength`` as it was called before. There is full legacy support for the old
     151``maxlength`` argument, but ``max_length`` is prefered to provide consistency around
     152Django.
     153
    149154``CommaSeparatedIntegerField``
    150155~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    151156
    152 A field of integers separated by commas. As in ``CharField``, the ``maxlength``
     157A field of integers separated by commas. As in ``CharField``, the ``max_length``
    153158argument is required.
    154159
    155160``DateField``
     
    188193~~~~~~~~~~~~~~
    189194
    190195A ``CharField`` that checks that the value is a valid e-mail address.
    191 This doesn't accept ``maxlength``; its ``maxlength`` is automatically set to
     196This doesn't accept ``max_length``; its ``max_length`` is automatically set to
    19219775.
    193198
    194199``FileField``
     
    362367containing only letters, numbers, underscores or hyphens. They're generally
    363368used in URLs.
    364369
    365 In the Django development version, you can specify ``maxlength``. If
    366 ``maxlength`` is not specified, Django will use a default length of 50. In
     370In the Django development version, you can specify ``max_length``. If
     371``max_length`` is not specified, Django will use a default length of 50. In
    367372previous Django versions, there's no way to override the length of 50.
    368373
    369374Implies ``db_index=True``.
     
    487492            ('M', 'Male'),
    488493            ('F', 'Female'),
    489494        )
    490         gender = models.CharField(maxlength=1, choices=GENDER_CHOICES)
     495        gender = models.CharField(max_length=1, choices=GENDER_CHOICES)
    491496
    492497or outside your model class altogether::
    493498
     
    496501        ('F', 'Female'),
    497502    )
    498503    class Foo(models.Model):
    499         gender = models.CharField(maxlength=1, choices=GENDER_CHOICES)
     504        gender = models.CharField(max_length=1, choices=GENDER_CHOICES)
    500505
    501506Finally, note that choices can be any iterable object -- not necessarily a
    502507list or tuple. This lets you construct choices dynamically. But if you find
     
    633638
    634639In this example, the verbose name is ``"Person's first name"``::
    635640
    636     first_name = models.CharField("Person's first name", maxlength=30)
     641    first_name = models.CharField("Person's first name", max_length=30)
    637642
    638643In this example, the verbose name is ``"first name"``::
    639644
    640     first_name = models.CharField(maxlength=30)
     645    first_name = models.CharField(max_length=30)
    641646
    642647``ForeignKey``, ``ManyToManyField`` and ``OneToOneField`` require the first
    643648argument to be a model class, so use the ``verbose_name`` keyword argument::
     
    918923Give your model metadata by using an inner ``class Meta``, like so::
    919924
    920925    class Foo(models.Model):
    921         bar = models.CharField(maxlength=30)
     926        bar = models.CharField(max_length=30)
    922927
    923928        class Meta:
    924929            # ...
     
    10841089inner ``"class Admin"``, like so::
    10851090
    10861091    class Person(models.Model):
    1087         first_name = models.CharField(maxlength=30)
    1088         last_name = models.CharField(maxlength=30)
     1092        first_name = models.CharField(max_length=30)
     1093        last_name = models.CharField(max_length=30)
    10891094
    10901095        class Admin:
    10911096            # Admin options go here
     
    12401245      Here's a full example model::
    12411246
    12421247          class Person(models.Model):
    1243               name = models.CharField(maxlength=50)
     1248              name = models.CharField(max_length=50)
    12441249              birthday = models.DateField()
    12451250
    12461251              class Admin:
     
    12571262      Here's a full example model::
    12581263
    12591264          class Person(models.Model):
    1260               first_name = models.CharField(maxlength=50)
    1261               last_name = models.CharField(maxlength=50)
    1262               color_code = models.CharField(maxlength=6)
     1265              first_name = models.CharField(max_length=50)
     1266              last_name = models.CharField(max_length=50)
     1267              color_code = models.CharField(max_length=6)
    12631268
    12641269              class Admin:
    12651270                  list_display = ('first_name', 'last_name', 'colored_name')
     
    12751280      Here's a full example model::
    12761281
    12771282          class Person(models.Model):
    1278               first_name = models.CharField(maxlength=50)
     1283              first_name = models.CharField(max_length=50)
    12791284              birthday = models.DateField()
    12801285
    12811286              class Admin:
     
    15301535            return result_list
    15311536
    15321537    class OpinionPoll(models.Model):
    1533         question = models.CharField(maxlength=200)
     1538        question = models.CharField(max_length=200)
    15341539        poll_date = models.DateField()
    15351540        objects = PollManager()
    15361541
    15371542    class Response(models.Model):
    15381543        poll = models.ForeignKey(Poll)
    1539         person_name = models.CharField(maxlength=50)
     1544        person_name = models.CharField(max_length=50)
    15401545        response = models.TextField()
    15411546
    15421547With this example, you'd use ``OpinionPoll.objects.with_counts()`` to return
     
    15521557example, using this model::
    15531558
    15541559    class Book(models.Model):
    1555         title = models.CharField(maxlength=100)
    1556         author = models.CharField(maxlength=50)
     1560        title = models.CharField(max_length=100)
     1561        author = models.CharField(max_length=50)
    15571562
    15581563...the statement ``Book.objects.all()`` will return all books in the database.
    15591564
     
    15711576
    15721577    # Then hook it into the Book model explicitly.
    15731578    class Book(models.Model):
    1574         title = models.CharField(maxlength=100)
    1575         author = models.CharField(maxlength=50)
     1579        title = models.CharField(max_length=100)
     1580        author = models.CharField(max_length=50)
    15761581
    15771582        objects = models.Manager() # The default manager.
    15781583        dahl_objects = DahlBookManager() # The Dahl-specific manager.
     
    16051610            return super(FemaleManager, self).get_query_set().filter(sex='F')
    16061611
    16071612    class Person(models.Model):
    1608         first_name = models.CharField(maxlength=50)
    1609         last_name = models.CharField(maxlength=50)
    1610         sex = models.CharField(maxlength=1, choices=(('M', 'Male'), ('F', 'Female')))
     1613        first_name = models.CharField(max_length=50)
     1614        last_name = models.CharField(max_length=50)
     1615        sex = models.CharField(max_length=1, choices=(('M', 'Male'), ('F', 'Female')))
    16111616        people = models.Manager()
    16121617        men = MaleManager()
    16131618        women = FemaleManager()
     
    16371642For example, this model has a few custom methods::
    16381643
    16391644    class Person(models.Model):
    1640         first_name = models.CharField(maxlength=50)
    1641         last_name = models.CharField(maxlength=50)
     1645        first_name = models.CharField(max_length=50)
     1646        last_name = models.CharField(max_length=50)
    16421647        birth_date = models.DateField()
    1643         address = models.CharField(maxlength=100)
    1644         city = models.CharField(maxlength=50)
     1648        address = models.CharField(max_length=100)
     1649        city = models.CharField(max_length=50)
    16451650        state = models.USStateField() # Yes, this is America-centric...
    16461651
    16471652        def baby_boomer_status(self):
     
    16811686For example::
    16821687
    16831688    class Person(models.Model):
    1684         first_name = models.CharField(maxlength=50)
    1685         last_name = models.CharField(maxlength=50)
     1689        first_name = models.CharField(max_length=50)
     1690        last_name = models.CharField(max_length=50)
    16861691
    16871692        def __str__(self):
    16881693            return '%s %s' % (self.first_name, self.last_name)
     
    17641769to happen whenever you save an object. For example::
    17651770
    17661771    class Blog(models.Model):
    1767         name = models.CharField(maxlength=100)
     1772        name = models.CharField(max_length=100)
    17681773        tagline = models.TextField()
    17691774
    17701775        def save(self):
     
    17751780You can also prevent saving::
    17761781
    17771782    class Blog(models.Model):
    1778         name = models.CharField(maxlength=100)
     1783        name = models.CharField(max_length=100)
    17791784        tagline = models.TextField()
    17801785
    17811786        def save(self):
  • docs/testing.txt

     
    7171        'The cat says "meow"'
    7272        """
    7373
    74         name = models.CharField(maxlength=20)
    75         sound = models.CharField(maxlength=20)
     74        name = models.CharField(max_length=20)
     75        sound = models.CharField(max_length=20)
    7676
    7777        def speak(self):
    7878            return 'The %s says "%s"' % (self.name, self.sound)
  • docs/forms.txt

     
    3737    )
    3838
    3939    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)
    4343        state = models.USStateField()
    44         zip_code = models.CharField(maxlength=5, blank=True)
     44        zip_code = models.CharField(max_length=5, blank=True)
    4545        place_type = models.IntegerField(choices=PLACE_TYPES)
    4646
    4747        class Admin:
     
    388388        def __init__(self):
    389389            self.fields = (
    390390                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),
    392392                forms.SelectField(field_name="urgency", choices=urgency_choices),
    393393                forms.LargeTextField(field_name="contents", is_required=True),
    394394            )
  • docs/sites.txt

     
    4646    from django.contrib.sites.models import Site
    4747
    4848    class Article(models.Model):
    49         headline = models.CharField(maxlength=200)
     49        headline = models.CharField(max_length=200)
    5050        # ...
    5151        sites = models.ManyToManyField(Site)
    5252
     
    8787    from django.contrib.sites.models import Site
    8888
    8989    class Article(models.Model):
    90         headline = models.CharField(maxlength=200)
     90        headline = models.CharField(max_length=200)
    9191        # ...
    9292        site = models.ForeignKey(Site)
    9393
     
    229229
    230230    class Photo(models.Model):
    231231        photo = models.FileField(upload_to='/home/photos')
    232         photographer_name = models.CharField(maxlength=100)
     232        photographer_name = models.CharField(max_length=100)
    233233        pub_date = models.DateField()
    234234        site = models.ForeignKey(Site)
    235235        objects = models.Manager()
     
    257257
    258258    class Photo(models.Model):
    259259        photo = models.FileField(upload_to='/home/photos')
    260         photographer_name = models.CharField(maxlength=100)
     260        photographer_name = models.CharField(max_length=100)
    261261        pub_date = models.DateField()
    262262        publish_on = models.ForeignKey(Site)
    263263        objects = models.Manager()
Back to Top