Django

Code

Ticket #2101: max_length+docs.patch

File max_length+docs.patch, 107.6 kB (added by Marc Fargas <telenieko@telenieko.com>, 2 years ago)

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

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

    old new  
    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

    old new  
    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

    old new  
    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

    old new  
    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

    old new  
    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

    old new  
    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

    old new  
    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

    old new  
    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

    old new  
    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

    old new  
    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

    old new  
    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

    old new  
    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

    old new  
    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

    old new  
    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

    old new  
    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

    old new  
    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

    old new  
    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

    old new  
    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

    old new  
    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

    old new  
    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

    old new  
    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

    old new  
    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

    old new  
    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

    old new  
    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

    old new  
    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     n