Django

Code

Ticket #2101: max_length.5.diff

File max_length.5.diff, 124.4 kB (added by gwilson, 3 years ago)

Use PendingDeprecationWarning instead of default UserWarning.

  • django/utils/maxlength.py

    old new  
     1""" 
     2Utilities for providing backwards compatibility for the maxlength argument, 
     3which has been replaced by max_length, see ticket #2101. 
     4""" 
     5 
     6from warnings import warn 
     7 
     8def get_maxlength(self): 
     9    return self.max_length 
     10 
     11def set_maxlength(self, value): 
     12    self.max_length = value 
     13 
     14def legacy_maxlength(max_length, maxlength): 
     15    """ 
     16    Consolidates max_length and maxlength, providing backwards compatibilty 
     17    for the legacy "maxlength" argument. 
     18    If one of max_length or maxlength is given, then that value is returned. 
     19    If both are given, a TypeError is raised. 
     20    If maxlength is used at all, a deprecation warning is issued. 
     21    """ 
     22    if maxlength is not None: 
     23        warn("maxlength is deprecated, use max_length instead.", 
     24             PendingDeprecationWarning, 
     25             stacklevel=3) 
     26        if max_length is not None: 
     27            raise TypeError("field can not take both the max_length" 
     28                            " argument and the legacy maxlength argument.") 
     29        max_length = maxlength 
     30    return max_length 
     31 
     32def remove_maxlength(func): 
     33    """ 
     34    A decorator to be used on a class's __init__ that provides backwards 
     35    compatibilty for the legacy "maxlength" keyword argument, i.e. 
     36      name = models.CharField(maxlength=20) 
     37    It does this by changing the passed "maxlength" keyword argument 
     38    (if it exists) into a "max_length" keyword argument. 
     39    """ 
     40    def inner(self, *args, **kwargs): 
     41        max_length = kwargs.get('max_length', None) 
     42        # pop maxlength because we don't want this going to __init__. 
     43        maxlength = kwargs.pop('maxlength', None) 
     44        max_length = legacy_maxlength(max_length, maxlength) 
     45        # Only set the max_length keyword argument if we got a value back. 
     46        if max_length is not None: 
     47            kwargs['max_length'] = max_length 
     48        func(self, *args, **kwargs) 
     49    return inner 
     50 
     51# This metaclass is used in two places, and should be removed when legacy 
     52# support for maxlength is dropped. 
     53#   * oldforms.FormField 
     54#   * db.models.fields.Field 
     55 
     56class LegacyMaxlength(type): 
     57    """ 
     58    Metaclass for providing backwards compatibility support for the 
     59    "maxlength" keyword argument. 
     60    """ 
     61     
     62    def __init__(cls, name, bases, attrs): 
     63        super(LegacyMaxlength, cls).__init__(name, bases, attrs) 
     64        # Decorate the class's __init__ to remove any maxlength keyword. 
     65        cls.__init__ = remove_maxlength(cls.__init__) 
     66        # Support accessing and setting to the legacy maxlength attribute. 
     67        cls.maxlength = property(get_maxlength, set_maxlength) 
  • tests/regressiontests/maxlength/tests.py

    old new  
     1# Test access to max_length while still providing full backwards compatibility 
     2# with legacy maxlength attribute. 
     3""" 
     4 
     5Don't print out the deprecation warnings during testing. 
     6>>> from warnings import filterwarnings 
     7>>> filterwarnings("ignore") 
     8 
     9# legacy_maxlength function 
     10 
     11>>> from django.utils.maxlength import legacy_maxlength 
     12 
     13>>> legacy_maxlength(None, None) 
     14 
     15 
     16>>> legacy_maxlength(10, None) 
     1710 
     18 
     19>>> legacy_maxlength(None, 10) 
     2010 
     21 
     22>>> legacy_maxlength(10, 12) 
     23Traceback (most recent call last): 
     24... 
     25TypeError: field can not take both the max_length argument and the legacy maxlength argument. 
     26 
     27>>> legacy_maxlength(0, 10) 
     28Traceback (most recent call last): 
     29... 
     30TypeError: field can not take both the max_length argument and the legacy maxlength argument. 
     31 
     32>>> legacy_maxlength(0, None) 
     330 
     34 
     35>>> legacy_maxlength(None, 0) 
     360 
     37 
     38#=============================================================================== 
     39# Fields 
     40#=============================================================================== 
     41 
     42# Set up fields 
     43>>> from django.db.models import fields 
     44>>> new = fields.Field(max_length=15) 
     45>>> old = fields.Field(maxlength=10) 
     46 
     47# Ensure both max_length and legacy maxlength are not able to both be specified 
     48>>> fields.Field(maxlength=10, max_length=15) 
     49Traceback (most recent call last): 
     50    ... 
     51TypeError: field can not take both the max_length argument and the legacy maxlength argument. 
     52 
     53# Test max_length 
     54>>> new.max_length 
     5515 
     56>>> old.max_length 
     5710 
     58 
     59# Test accessing maxlength 
     60>>> new.maxlength 
     6115 
     62>>> old.maxlength 
     6310 
     64 
     65# Test setting maxlength 
     66>>> new.maxlength += 1 
     67>>> old.maxlength += 1 
     68>>> new.max_length 
     6916 
     70>>> old.max_length 
     7111 
     72 
     73# SlugField __init__ passes through max_length so test that too 
     74>>> fields.SlugField('new', max_length=15).max_length 
     7515 
     76>>> fields.SlugField('empty').max_length 
     7750 
     78>>> fields.SlugField('old', maxlength=10).max_length 
     7910 
     80 
     81#=============================================================================== 
     82# (old)forms 
     83#=============================================================================== 
     84 
     85>>> from django import oldforms 
     86 
     87# Test max_length attribute 
     88 
     89>>> oldforms.TextField('new', max_length=15).render('') 
     90u'<input type="text" id="id_new" class="vTextField" name="new" size="30" value="" maxlength="15" />' 
     91 
     92>>> oldforms.IntegerField('new', max_length=15).render('') 
     93u'<input type="text" id="id_new" class="vIntegerField" name="new" size="10" value="" maxlength="15" />' 
     94 
     95>>> oldforms.SmallIntegerField('new', max_length=15).render('') 
     96u'<input type="text" id="id_new" class="vSmallIntegerField" name="new" size="5" value="" maxlength="15" />' 
     97 
     98>>> oldforms.PositiveIntegerField('new', max_length=15).render('') 
     99u'<input type="text" id="id_new" class="vPositiveIntegerField" name="new" size="10" value="" maxlength="15" />' 
     100 
     101>>> oldforms.PositiveSmallIntegerField('new', max_length=15).render('') 
     102u'<input type="text" id="id_new" class="vPositiveSmallIntegerField" name="new" size="5" value="" maxlength="15" />' 
     103 
     104>>> oldforms.DatetimeField('new', max_length=15).render('') 
     105u'<input type="text" id="id_new" class="vDatetimeField" name="new" size="30" value="" maxlength="15" />' 
     106 
     107>>> oldforms.EmailField('new', max_length=15).render('') 
     108u'<input type="text" id="id_new" class="vEmailField" name="new" size="50" value="" maxlength="15" />' 
     109>>> oldforms.EmailField('new').render('') 
     110u'<input type="text" id="id_new" class="vEmailField" name="new" size="50" value="" maxlength="75" />' 
     111 
     112>>> oldforms.URLField('new', max_length=15).render('') 
     113u'<input type="text" id="id_new" class="vURLField" name="new" size="50" value="" maxlength="15" />' 
     114>>> oldforms.URLField('new').render('') 
     115u'<input type="text" id="id_new" class="vURLField" name="new" size="50" value="" maxlength="200" />' 
     116 
     117>>> oldforms.IPAddressField('new', max_length=15).render('') 
     118u'<input type="text" id="id_new" class="vIPAddressField" name="new" size="15" value="" maxlength="15" />' 
     119>>> oldforms.IPAddressField('new').render('') 
     120u'<input type="text" id="id_new" class="vIPAddressField" name="new" size="15" value="" maxlength="15" />' 
     121 
     122>>> oldforms.CommaSeparatedIntegerField('new', max_length=15).render('') 
     123u'<input type="text" id="id_new" class="vCommaSeparatedIntegerField" name="new" size="20" value="" maxlength="15" />' 
     124 
     125 
     126# Test legacy maxlength attribute 
     127 
     128>>> oldforms.TextField('old', maxlength=10).render('') 
     129u'<input type="text" id="id_old" class="vTextField" name="old" size="30" value="" maxlength="10" />' 
     130 
     131>>> oldforms.IntegerField('old', maxlength=10).render('') 
     132u'<input type="text" id="id_old" class="vIntegerField" name="old" size="10" value="" maxlength="10" />' 
     133 
     134>>> oldforms.SmallIntegerField('old', maxlength=10).render('') 
     135u'<input type="text" id="id_old" class="vSmallIntegerField" name="old" size="5" value="" maxlength="10" />' 
     136 
     137>>> oldforms.PositiveIntegerField('old', maxlength=10).render('') 
     138u'<input type="text" id="id_old" class="vPositiveIntegerField" name="old" size="10" value="" maxlength="10" />' 
     139 
     140>>> oldforms.PositiveSmallIntegerField('old', maxlength=10).render('') 
     141u'<input type="text" id="id_old" class="vPositiveSmallIntegerField" name="old" size="5" value="" maxlength="10" />' 
     142 
     143>>> oldforms.DatetimeField('old', maxlength=10).render('') 
     144u'<input type="text" id="id_old" class="vDatetimeField" name="old" size="30" value="" maxlength="10" />' 
     145 
     146>>> oldforms.EmailField('old', maxlength=10).render('') 
     147u'<input type="text" id="id_old" class="vEmailField" name="old" size="50" value="" maxlength="10" />' 
     148 
     149>>> oldforms.URLField('old', maxlength=10).render('') 
     150u'<input type="text" id="id_old" class="vURLField" name="old" size="50" value="" maxlength="10" />' 
     151 
     152>>> oldforms.IPAddressField('old', maxlength=10).render('') 
     153u'<input type="text" id="id_old" class="vIPAddressField" name="old" size="15" value="" maxlength="10" />' 
     154 
     155>>> oldforms.CommaSeparatedIntegerField('old', maxlength=10).render('') 
     156u'<input type="text" id="id_old" class="vCommaSeparatedIntegerField" name="old" size="20" value="" maxlength="10" />' 
     157""" 
     158if __name__ == "__main__": 
     159    import doctest 
     160    doctest.testmod() 
  • django/contrib/admin/models.py

    old new  
    1818    user = models.ForeignKey(User) 
    1919    content_type = models.ForeignKey(ContentType, blank=True, null=True) 
    2020    object_id = models.TextField(_('object id'), blank=True, null=True) 
    21     object_repr = models.CharField(_('object repr'), maxlength=200) 
     21    object_repr = models.CharField(_('object repr'), max_length=200) 
    2222    action_flag = models.PositiveSmallIntegerField(_('action flag')) 
    2323    change_message = models.TextField(_('change message'), blank=True) 
    2424    objects = LogEntryManager() 
  • django/contrib/admin/templatetags/admin_modify.py

    old new  
    192192            t.append(u'document.getElementById("id_%s").onkeyup = function() {' \ 
    193193                     ' var e = document.getElementById("id_%s");' \ 
    194194                     ' if(!e._changed) { e.value = URLify(%s, %s);} }; ' % ( 
    195                      f, field.name, add_values, field.maxlength)) 
     195                     f, field.name, add_values, field.max_length)) 
    196196    return u''.join(t) 
    197197auto_populated_field_script = register.simple_tag(auto_populated_field_script) 
    198198 
  • django/contrib/admin/views/doc.py

    old new  
    291291DATA_TYPE_MAPPING = { 
    292292    'AutoField'                 : _('Integer'), 
    293293    'BooleanField'              : _('Boolean (Either True or False)'), 
    294     'CharField'                 : _('String (up to %(maxlength)s)'), 
     294    'CharField'                 : _('String (up to %(max_length)s)'), 
    295295    'CommaSeparatedIntegerField': _('Comma-separated integers'), 
    296296    'DateField'                 : _('Date (without time)'), 
    297297    'DateTimeField'             : _('Date (with time)'), 
     
    310310    'PhoneNumberField'          : _('Phone number'), 
    311311    'PositiveIntegerField'      : _('Integer'), 
    312312    'PositiveSmallIntegerField' : _('Integer'), 
    313     'SlugField'                 : _('String (up to %(maxlength)s)'), 
     313    'SlugField'                 : _('String (up to %(max_length)s)'), 
    314314    'SmallIntegerField'         : _('Integer'), 
    315315    'TextField'                 : _('Text'), 
    316316    'TimeField'                 : _('Time'), 
  • django/contrib/auth/forms.py

    old new  
    1010    "A form that creates a user, with no privileges, from the given username and password." 
    1111    def __init__(self): 
    1212        self.fields = ( 
    13             oldforms.TextField(field_name='username', length=30, maxlength=30, is_required=True, 
     13            oldforms.TextField(field_name='username', length=30, max_length=30, is_required=True, 
    1414                validator_list=[validators.isAlphaNumeric, self.isValidUsername]), 
    15             oldforms.PasswordField(field_name='password1', length=30, maxlength=60, is_required=True), 
    16             oldforms.PasswordField(field_name='password2', length=30, maxlength=60, is_required=True, 
     15            oldforms.PasswordField(field_name='password1', length=30, max_length=60, is_required=True), 
     16            oldforms.PasswordField(field_name='password2', length=30, max_length=60, is_required=True, 
    1717                validator_list=[validators.AlwaysMatchesOtherField('password1', _("The two password fields didn't match."))]), 
    1818        ) 
    1919 
     
    4242        """ 
    4343        self.request = request 
    4444        self.fields = [ 
    45             oldforms.TextField(field_name="username", length=15, maxlength=30, is_required=True, 
     45            oldforms.TextField(field_name="username", length=15, max_length=30, is_required=True, 
    4646                validator_list=[self.isValidUser, self.hasCookiesEnabled]), 
    47             oldforms.PasswordField(field_name="password", length=15, maxlength=30, is_required=True), 
     47            oldforms.PasswordField(field_name="password", length=15, max_length=30, is_required=True), 
    4848        ] 
    4949        self.user_cache = None 
    5050 
     
    111111    def __init__(self, user): 
    112112        self.user = user 
    113113        self.fields = ( 
    114             oldforms.PasswordField(field_name="old_password", length=30, maxlength=30, is_required=True, 
     114            oldforms.PasswordField(field_name="old_password", length=30, max_length=30, is_required=True, 
    115115                validator_list=[self.isValidOldPassword]), 
    116             oldforms.PasswordField(field_name="new_password1", length=30, maxlength=30, is_required=True, 
     116            oldforms.PasswordField(field_name="new_password1", length=30, max_length=30, is_required=True, 
    117117                validator_list=[validators.AlwaysMatchesOtherField('new_password2', _("The two 'new password' fields didn't match."))]), 
    118             oldforms.PasswordField(field_name="new_password2", length=30, maxlength=30, is_required=True), 
     118            oldforms.PasswordField(field_name="new_password2", length=30, max_length=30, is_required=True), 
    119119        ) 
    120120 
    121121    def isValidOldPassword(self, new_data, all_data): 
     
    133133    def __init__(self, user): 
    134134        self.user = user 
    135135        self.fields = ( 
    136             oldforms.PasswordField(field_name='password1', length=30, maxlength=60, is_required=True), 
    137             oldforms.PasswordField(field_name='password2', length=30, maxlength=60, is_required=True, 
     136            oldforms.PasswordField(field_name='password1', length=30, max_length=60, is_required=True), 
     137            oldforms.PasswordField(field_name='password2', length=30, max_length=60, is_required=True, 
    138138                validator_list=[validators.AlwaysMatchesOtherField('password1', _("The two password fields didn't match."))]), 
    139139        ) 
    140140 
  • django/contrib/auth/models.py

    old new  
    5050 
    5151    Three basic permissions -- add, change and delete -- are automatically created for each Django model. 
    5252    """ 
    53     name = models.CharField(_('name'), maxlength=50) 
     53    name = models.CharField(_('name'), max_length=50) 
    5454    content_type = models.ForeignKey(ContentType) 
    55     codename = models.CharField(_('codename'), maxlength=100) 
     55    codename = models.CharField(_('codename'), max_length=100) 
    5656 
    5757    class Meta: 
    5858        verbose_name = _('permission') 
     
    7070 
    7171    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. 
    7272    """ 
    73     name = models.CharField(_('name'), maxlength=80, unique=True) 
     73    name = models.CharField(_('name'), max_length=80, unique=True) 
    7474    permissions = models.ManyToManyField(Permission, verbose_name=_('permissions'), blank=True, filter_interface=models.HORIZONTAL) 
    7575 
    7676    class Meta: 
     
    108108 
    109109    Username and password are required. Other fields are optional. 
    110110    """ 
    111     username = models.CharField(_('username'), maxlength=30, unique=True, validator_list=[validators.isAlphaNumeric], help_text=_("Required. 30 characters or fewer. Alphanumeric characters only (letters, digits and underscores).")) 
    112     first_name = models.CharField(_('first name'), maxlength=30, blank=True) 
    113     last_name = models.CharField(_('last name'), maxlength=30, blank=True) 
     111    username = models.CharField(_('username'), max_length=30, unique=True, validator_list=[validators.isAlphaNumeric], help_text=_("Required. 30 characters or fewer. Alphanumeric characters only (letters, digits and underscores).")) 
     112    first_name = models.CharField(_('first name'), max_length=30, blank=True) 
     113    last_name = models.CharField(_('last name'), max_length=30, blank=True) 
    114114    email = models.EmailField(_('e-mail address'), blank=True) 
    115     password = models.CharField(_('password'), maxlength=128, help_text=_("Use '[algo]$[salt]$[hexdigest]' or use the <a href=\"password/\">change password form</a>.")) 
     115    password = models.CharField(_('password'), max_length=128, help_text=_("Use '[algo]$[salt]$[hexdigest]' or use the <a href=\"password/\">change password form</a>.")) 
    116116    is_staff = models.BooleanField(_('staff status'), default=False, help_text=_("Designates whether the user can log into this admin site.")) 
    117117    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.")) 
    118118    is_superuser = models.BooleanField(_('superuser status'), default=False, help_text=_("Designates that this user has all permissions without explicitly assigning them.")) 
  • 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  
    2929            else: 
    3030                return [] 
    3131        self.fields.extend([ 
    32             oldforms.LargeTextField(field_name="comment", maxlength=3000, is_required=True, 
     32            oldforms.LargeTextField(field_name="comment", max_length=3000, is_required=True, 
    3333                validator_list=[self.hasNoProfanities]), 
    3434            oldforms.RadioSelectField(field_name="rating1", choices=choices, 
    3535                is_required=ratings_required and num_rating_choices > 0, 
     
    122122    "Manipulator that handles public free (unregistered) comments" 
    123123    def __init__(self): 
    124124        self.fields = ( 
    125             oldforms.TextField(field_name="person_name", maxlength=50, is_required=True, 
     125            oldforms.TextField(field_name="person_name", max_length=50, is_required=True, 
    126126                validator_list=[self.hasNoProfanities]), 
    127             oldforms.LargeTextField(field_name="comment", maxlength=3000, is_required=True, 
     127            oldforms.LargeTextField(field_name="comment", max_length=3000, is_required=True, 
    128128                validator_list=[self.hasNoProfanities]), 
    129129        ) 
    130130 
  • django/contrib/contenttypes/models.py

    old new  
    3232        CONTENT_TYPE_CACHE = {} 
    3333 
    3434class ContentType(models.Model): 
    35     name = models.CharField(maxlength=100) 
    36     app_label = models.CharField(maxlength=100) 
    37     model = models.CharField(_('python model class name'), maxlength=100) 
     35    name = models.CharField(max_length=100) 
     36    app_label = models.CharField(max_length=100) 
     37    model = models.CharField(_('python model class name'), max_length=100) 
    3838    objects = ContentTypeManager() 
    3939    class Meta: 
    4040        verbose_name = _('content type') 
  • django/contrib/flatpages/models.py

    old new  
    44from django.utils.translation import ugettext_lazy as _ 
    55 
    66class FlatPage(models.Model): 
    7     url = models.CharField(_('URL'), maxlength=100, validator_list=[validators.isAlphaNumericURL], db_index=True, 
     7    url = models.CharField(_('URL'), max_length=100, validator_list=[validators.isAlphaNumericURL], db_index=True, 
    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/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/sessions/models.py

    old new  
    6565    the sessions documentation that is shipped with Django (also available 
    6666    on the Django website). 
    6767    """ 
    68     session_key = models.CharField(_('session key'), maxlength=40, primary_key=True) 
     68    session_key = models.CharField(_('session key'), max_length=40, primary_key=True) 
    6969    session_data = models.TextField(_('session data')) 
    7070    expire_date = models.DateTimeField(_('expire date')) 
    7171    objects = SessionManager() 
  • django/contrib/sites/models.py

    old new  
    1212        return self.get(pk=sid) 
    1313 
    1414class Site(models.Model): 
    15     domain = models.CharField(_('domain name'), maxlength=100) 
    16     name = models.CharField(_('display name'), maxlength=50) 
     15    domain = models.CharField(_('domain name'), max_length=100) 
     16    name = models.CharField(_('display name'), max_length=50) 
    1717    objects = SiteManager() 
    1818    class Meta: 
    1919        db_table = 'django_site' 
  • django/core/management.py

    old new  
    910910                    field_type, new_params = field_type 
    911911                    extra_params.update(new_params) 
    912912 
    913                 # Add maxlength for all CharFields. 
     913                # Add max_length for all CharFields. 
    914914                if field_type == 'CharField' and row[3]: 
    915                     extra_params['maxlength'] = row[3] 
     915                    extra_params['max_length'] = row[3] 
    916916 
    917917                if field_type == 'DecimalField': 
    918918                    extra_params['max_digits'] = row[4] 
     
    987987        for f in opts.fields: 
    988988            if f.name == 'id' and not f.primary_key and opts.pk.name == 'id': 
    989989                e.add(opts, '"%s": You can\'t use "id" as a field name, because each model automatically gets an "id" field if none of the fields have primary_key=True. You need to either remove/rename your "id" field or add primary_key=True to a field.' % f.name) 
    990             if isinstance(f, models.CharField) and f.maxlength in (None, 0): 
    991                 e.add(opts, '"%s": CharFields require a "maxlength" attribute.' % f.name) 
     990            if isinstance(f, models.CharField) and f.max_length in (None, 0): 
     991                e.add(opts, '"%s": CharFields require a "max_length" attribute.' % f.name) 
    992992            if isinstance(f, models.DecimalField): 
    993993                if f.decimal_places is None: 
    994994                    e.add(opts, '"%s": DecimalFields require a "decimal_places" attribute.' % f.name) 
     
    10131013            if f.db_index not in (None, True, False): 
    10141014                e.add(opts, '"%s": "db_index" should be either None, True or False.' % f.name) 
    10151015 
    1016             # Check that maxlength <= 255 if using older MySQL versions. 
     1016            # Check that max_length <= 255 if using older MySQL versions. 
    10171017            if settings.DATABASE_ENGINE == 'mysql': 
    10181018                db_version = connection.get_server_version() 
    1019                 if db_version < (5, 0, 3) and isinstance(f, (models.CharField, models.CommaSeparatedIntegerField, models.SlugField)) and f.maxlength > 255: 
    1020                     e.add(opts, '"%s": %s cannot have a "maxlength" greater than 255 when you are using a version of MySQL prior to 5.0.3 (you are using %s).' % (f.name, f.__class__.__name__, '.'.join([str(n) for n in db_version[:3]]))) 
     1019                if db_version < (5, 0, 3) and isinstance(f, (models.CharField, models.CommaSeparatedIntegerField, models.SlugField)) and f.max_length > 255: 
     1020                    e.add(opts, '"%s": %s cannot have a "max_length" greater than 255 when you are using a version of MySQL prior to 5.0.3 (you are using %s).' % (f.name, f.__class__.__name__, '.'.join([str(n) for n in db_version[:3]]))) 
    10211021 
    10221022            # Check to see if the related field will clash with any 
    10231023            # existing fields, m2m fields, m2m related objects or related objects 
     
    12521252    from django.db import backend, connection, transaction, models 
    12531253    fields = ( 
    12541254        # "key" is a reserved word in MySQL, so use "cache_key" instead. 
    1255         models.CharField(name='cache_key', maxlength=255, unique=True, primary_key=True), 
     1255        models.CharField(name='cache_key', max_length=255, unique=True, primary_key=True), 
    12561256        models.TextField(name='value'), 
    12571257        models.DateTimeField(name='expires', db_index=True), 
    12581258    ) 
  • 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    'DecimalField':      'numeric(%(max_digits)s, %(decimal_places)s)', 
     
    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/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    'DecimalField':      'numeric(%(max_digits)s, %(decimal_places)s)', 
     
    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/mysql_old/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    'DecimalField':      'numeric(%(max_digits)s, %(decimal_places)s)', 
     
    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  
    88DATA_TYPES = { 
    99    'AutoField':                    'NUMBER(11)', 
    1010    'BooleanField':                 'NUMBER(1) CHECK (%(column)s IN (0,1))', 
    11     'CharField':                    'NVARCHAR2(%(maxlength)s)', 
    12     'CommaSeparatedIntegerField':   'VARCHAR2(%(maxlength)s)', 
     11    'CharField':                    'NVARCHAR2(%(max_length)s)', 
     12    'CommaSeparatedIntegerField':   'VARCHAR2(%(max_length)s)', 
    1313    'DateField':                    'DATE', 
    1414    'DateTimeField':                'TIMESTAMP', 
    1515    'DecimalField':                 'NUMBER(%(max_digits)s, %(decimal_places)s)', 
  • 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    'DecimalField':      'numeric(%(max_digits)s, %(decimal_places)s)', 
     
    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/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    'DecimalField':                 'decimal', 
     
    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/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/models/fields/__init__.py

    old new  
    1111from django.utils.text import capfirst 
    1212from django.utils.translation import ugettext_lazy, ugettext as _ 
    1313from django.utils.encoding import smart_unicode, force_unicode, smart_str 
     14from django.utils.maxlength import LegacyMaxlength 
    1415import datetime, os, time 
    1516try: 
    1617    import decimal 
     
    6364#     getattr(obj, opts.pk.attname) 
    6465 
    6566class Field(object): 
    66  
     67    # Provide backwards compatibility for the maxlength attribute and 
     68    # argument for this class and all subclasses. 
     69    __metaclass__ = LegacyMaxlength 
     70     
    6771    # Designates whether empty strings fundamentally are allowed at the 
    6872    # database level. 
    6973    empty_strings_allowed = True 
     
    7276    creation_counter = 0 
    7377 
    7478    def __init__(self, verbose_name=None, name=None, primary_key=False, 
    75         maxlength=None, unique=False, blank=False, null=False, db_index=False, 
     79        max_length=None, unique=False, blank=False, null=False, db_index=False, 
    7680        core=False, rel=None, default=NOT_PROVIDED, editable=True, serialize=True, 
    7781        prepopulate_from=None, unique_for_date=None, unique_for_month=None, 
    7882        unique_for_year=None, validator_list=None, choices=None, radio_admin=None, 
     
    8084        self.name = name 
    8185        self.verbose_name = verbose_name 
    8286        self.primary_key = primary_key 
    83         self.maxlength, self.unique = maxlength, unique 
     87        self.max_length, self.unique = max_length, unique 
    8488        self.blank, self.null = blank, null 
    8589        # Oracle treats the empty string ('') as null, so coerce the null 
    8690        # option whenever '' is a possible value. 
     
    244248 
    245249    def prepare_field_objs_and_params(self, manipulator, name_prefix): 
    246250        params = {'validator_list': self.validator_list[:]} 
    247         if self.maxlength and not self.choices: # Don't give SelectFields a maxlength parameter. 
    248             params['maxlength'] = self.maxlength 
     251        if self.max_length and not self.choices: # Don't give SelectFields a max_length parameter. 
     252            params['max_length'] = self.max_length 
    249253 
    250254        if self.choices: 
    251255            if self.radio_admin: 
     
    461465        return smart_unicode(value) 
    462466 
    463467    def formfield(self, **kwargs): 
    464         defaults = {'max_length': self.maxlength} 
     468        defaults = {'max_length': self.max_length} 
    465469        defaults.update(kwargs) 
    466470        return super(CharField, self).formfield(**defaults) 
    467471 
     
    670674 
    671675class EmailField(CharField): 
    672676    def __init__(self, *args, **kwargs): 
    673         kwargs['maxlength'] = 75 
     677        kwargs['max_length'] = 75 
    674678        CharField.__init__(self, *args, **kwargs) 
    675679 
    676680    def get_internal_type(self): 
     
    829833class IPAddressField(Field): 
    830834    empty_strings_allowed = False 
    831835    def __init__(self, *args, **kwargs): 
    832         kwargs['maxlength'] = 15 
     836        kwargs['max_length'] = 15 
    833837        Field.__init__(self, *args, **kwargs) 
    834838 
    835839    def get_manipulator_field_objs(self): 
     
    877881 
    878882class SlugField(Field): 
    879883    def __init__(self, *args, **kwargs): 
    880         kwargs['maxlength'] = kwargs.get('maxlength', 50) 
     884        kwargs['max_length'] = kwargs.get('max_length', 50) 
    881885        kwargs.setdefault('validator_list', []).append(validators.isSlug) 
    882886        # Set db_index=True unless it's been set manually. 
    883887        if 'db_index' not in kwargs: 
     
    963967 
    964968class URLField(CharField): 
    965969    def __init__(self, verbose_name=None, name=None, verify_exists=True, **kwargs): 
    966         kwargs['maxlength'] = kwargs.get('maxlength', 200) 
     970        kwargs['max_length'] = kwargs.get('max_length', 200) 
    967971        if verify_exists: 
    968972            kwargs.setdefault('validator_list', []).append(validators.isExistingURL) 
    969973        self.verify_exists = verify_exists 
  • django/newforms/fields.py

    old new  
    120120 
    121121    def widget_attrs(self, widget): 
    122122        if self.max_length is not None and isinstance(widget, (TextInput, PasswordInput)): 
     123            # The HTML attribute is maxlength, not max_length. 
    123124            return {'maxlength': str(self.max_length)} 
    124125 
    125126class IntegerField(Field): 
  • django/oldforms/__init__.py

    old new  
    44from django.conf import settings 
    55from django.utils.translation import ugettext, ungettext 
    66from django.utils.encoding import smart_unicode, force_unicode 
     7from django.utils.maxlength import LegacyMaxlength 
    78 
    89FORM_FIELD_ID_PREFIX = 'id_' 
    910 
     
    302303    Subclasses should also implement a render(data) method, which is responsible 
    303304    for rending the form field in XHTML. 
    304305    """ 
     306    # Provide backwards compatibility for the maxlength attribute and 
     307    # argument for this class and all subclasses. 
     308    __metaclass__ = LegacyMaxlength 
    305309 
    306310    def __str__(self): 
    307311        return unicode(self).encode('utf-8') 
     
    390394 
    391395class TextField(FormField): 
    392396    input_type = "text" 
    393     def __init__(self, field_name, length=30, maxlength=None, is_required=False, validator_list=None, member_name=None): 
     397    def __init__(self, field_name, length=30, max_length=None, is_required=False, validator_list=None, member_name=None): 
    394398        if validator_list is None: validator_list = [] 
    395399        self.field_name = field_name 
    396         self.length, self.maxlength = length, maxlength 
     400        self.length, self.max_length = length, max_length 
    397401        self.is_required = is_required 
    398402        self.validator_list = [self.isValidLength, self.hasNoNewlines] + validator_list 
    399403        if member_name != None: 
    400404            self.member_name = member_name 
    401405 
    402406    def isValidLength(self, data, form): 
    403         if data and self.maxlength and len(smart_unicode(data)) > self.maxlength: 
     407        if data and self.max_length and len(smart_unicode(data)) > self.max_length: 
    404408            raise validators.ValidationError, ungettext("Ensure your text is less than %s character.", 
    405                 "Ensure your text is less than %s characters.", self.maxlength) % self.maxlength 
     409                "Ensure your text is less than %s characters.", self.max_length) % self.max_length 
    406410 
    407411    def hasNoNewlines(self, data, form): 
    408412        if data and '\n' in data: 
     
    411415    def render(self, data): 
    412416        if data is None: 
    413417            data = u'' 
    414         maxlength = u'' 
    415         if self.maxlength: 
    416             maxlength = u'maxlength="%s" ' % self.maxlength 
     418        max_length = u'' 
     419        if self.max_length: 
     420            max_length = u'maxlength="%s" ' % self.max_length 
    417421        return u'<input type="%s" id="%s" class="v%s%s" name="%s" size="%s" value="%s" %s/>' % \ 
    418422            (self.input_type, self.get_id(), self.__class__.__name__, self.is_required and u' required' or '', 
    419             self.field_name, self.length, escape(data), maxlength) 
     423            self.field_name, self.length, escape(data), max_length) 
    420424 
    421425    def html2python(data): 
    422426        return data 
     
    426430    input_type = "password" 
    427431 
    428432class LargeTextField(TextField): 
    429     def __init__(self, field_name, rows=10, cols=40, is_required=False, validator_list=None, maxlength=None): 
     433    def __init__(self, field_name, rows=10, cols=40, is_required=False, validator_list=None, max_length=None): 
    430434        if validator_list is None: validator_list = [] 
    431435        self.field_name = field_name 
    432436        self.rows, self.cols, self.is_required = rows, cols, is_required 
    433437        self.validator_list = validator_list[:] 
    434         if maxlength: 
     438        if max_length: 
    435439            self.validator_list.append(self.isValidLength) 
    436             self.maxlength = maxlength 
     440            self.max_length = max_length 
    437441 
    438442    def render(self, data): 
    439443        if data is None: 
     
    710714#################### 
    711715 
    712716class IntegerField(TextField): 
    713     def __init__(self, field_name, length=10, maxlength=None, is_required=False, validator_list=None, member_name=None): 
     717    def __init__(self, field_name, length=10, max_length=None, is_required=False, validator_list=None, member_name=None): 
    714718        if validator_list is None: validator_list = [] 
    715719        validator_list = [self.isInteger] + validator_list 
    716720        if member_name is not None: 
    717721            self.member_name = member_name 
    718         TextField.__init__(self, field_name, length, maxlength, is_required, validator_list) 
     722        TextField.__init__(self, field_name, length, max_length, is_required, validator_list) 
    719723 
    720724    def isInteger(self, field_data, all_data): 
    721725        try: 
     
    730734    html2python = staticmethod(html2python) 
    731735 
    732736class SmallIntegerField(IntegerField): 
    733     def __init__(self, field_name, length=5, maxlength=5, is_required=False, validator_list=None): 
     737    def __init__(self, field_name, length=5, max_length=5, is_required=False, validator_list=None): 
    734738        if validator_list is None: validator_list = [] 
    735739        validator_list = [self.isSmallInteger] + validator_list 
    736         IntegerField.__init__(self, field_name, length, maxlength, is_required, validator_list) 
     740        IntegerField.__init__(self, field_name, length, max_length, is_required, validator_list) 
    737741 
    738742    def isSmallInteger(self, field_data, all_data): 
    739743        if not -32768 <= int(field_data) <= 32767: 
    740744            raise validators.CriticalValidationError, ugettext("Enter a whole number between -32,768 and 32,767.") 
    741745 
    742746class PositiveIntegerField(IntegerField): 
    743     def __init__(self, field_name, length=10, maxlength=None, is_required=False, validator_list=None): 
     747    def __init__(self, field_name, length=10, max_length=None, is_required=False, validator_list=None): 
    744748        if validator_list is None: validator_list = [] 
    745749        validator_list = [self.isPositive] + validator_list 
    746         IntegerField.__init__(self, field_name, length, maxlength, is_required, validator_list) 
     750        IntegerField.__init__(self, field_name, length, max_length, is_required, validator_list) 
    747751 
    748752    def isPositive(self, field_data, all_data): 
    749753        if int(field_data) < 0: 
    750754            raise validators.CriticalValidationError, ugettext("Enter a positive number.") 
    751755 
    752756class PositiveSmallIntegerField(IntegerField): 
    753     def __init__(self, field_name, length=5, maxlength=None, is_required=False, validator_list=None): 
     757    def __init__(self, field_name, length=5, max_length=None, is_required=False, validator_list=None): 
    754758        if validator_list is None: validator_list = [] 
    755759        validator_list = [self.isPositiveSmall] + validator_list 
    756         IntegerField.__init__(self, field_name, length, maxlength, is_required, validator_list) 
     760        IntegerField.__init__(self, field_name, length, max_length, is_required, validator_list) 
    757761 
    758762    def isPositiveSmall(self, field_data, all_data): 
    759763        if not 0 <= int(field_data) <= 32767: 
     
    806810class DatetimeField(TextField): 
    807811    """A FormField that automatically converts its data to a datetime.datetime object. 
    808812    The data should be in the format YYYY-MM-DD HH:MM:SS.""" 
    809     def __init__(self, field_name, length=30, maxlength=None, is_required=False, validator_list=None): 
     813    def __init__(self, field_name, length=30, max_length=None, is_required=False, validator_list=None): 
    810814        if validator_list is None: validator_list = [] 
    811815        self.field_name = field_name 
    812         self.length, self.maxlength = length, maxlength 
     816        self.length, self.max_length = length, max_length 
    813817        self.is_required = is_required 
    814818        self.validator_list = [validators.isValidANSIDatetime] + validator_list 
    815819 
     
    836840    def __init__(self, field_name, is_required=False, validator_list=None): 
    837841        if validator_list is None: validator_list = [] 
    838842        validator_list = [self.isValidDate] + validator_list 
    839         TextField.__init__(self, field_name, length=10, maxlength=10, 
     843        TextField.__init__(self, field_name, length=10, max_length=10, 
    840844            is_required=is_required, validator_list=validator_list) 
    841845 
    842846    def isValidDate(self, field_data, all_data): 
     
    861865    def __init__(self, field_name, is_required=False, validator_list=None): 
    862866        if validator_list is None: validator_list = [] 
    863867        validator_list = [self.isValidTime] + validator_list 
    864         TextField.__init__(self, field_name, length=8, maxlength=8, 
     868        TextField.__init__(self, field_name, length=8, max_length=8, 
    865869            is_required=is_required, validator_list=validator_list) 
    866870 
    867871    def isValidTime(self, field_data, all_data): 
     
    893897 
    894898class EmailField(TextField): 
    895899    "A convenience FormField for validating e-mail addresses" 
    896     def __init__(self, field_name, length=50, maxlength=75, is_required=False, validator_list=None): 
     900    def __init__(self, field_name, length=50, max_length=75, is_required=False, validator_list=None): 
    897901        if validator_list is None: validator_list = [] 
    898902        validator_list = [self.isValidEmail] + validator_list 
    899         TextField.__init__(self, field_name, length, maxlength=maxlength, 
     903        TextField.__init__(self, field_name, length, max_length=max_length, 
    900904            is_required=is_required, validator_list=validator_list) 
    901905 
    902906    def isValidEmail(self, field_data, all_data): 
     
    907911 
    908912class URLField(TextField): 
    909913    "A convenience FormField for validating URLs" 
    910     def __init__(self, field_name, length=50, maxlength=200, is_required=False, validator_list=None): 
     914    def __init__(self, field_name, length=50, max_length=200, is_required=False, validator_list=None): 
    911915        if validator_list is None: validator_list = [] 
    912916        validator_list = [self.isValidURL] + validator_list 
    913         TextField.__init__(self, field_name, length=length, maxlength=maxlength, 
     917        TextField.__init__(self, field_name, length=length, max_length=max_length, 
    914918            is_required=is_required, validator_list=validator_list) 
    915919 
    916920    def isValidURL(self, field_data, all_data): 
     
    920924            raise validators.CriticalValidationError, e.messages 
    921925 
    922926class IPAddressField(TextField): 
    923     def __init__(self, field_name, length=15, maxlength=15, is_required=False, validator_list=None): 
     927    def __init__(self, field_name, length=15, max_length=15, is_required=False, validator_list=None): 
    924928        if validator_list is None: validator_list = [] 
    925929        validator_list = [self.isValidIPAddress] + validator_list 
    926         TextField.__init__(self, field_name, length=length, maxlength=maxlength, 
     930        TextField.__init__(self, field_name, length=length, max_length=max_length, 
    927931            is_required=is_required, validator_list=validator_list) 
    928932 
    929933    def isValidIPAddress(self, field_data, all_data): 
     
    970974    def __init__(self, field_name, is_required=False, validator_list=None): 
    971975        if validator_list is None: validator_list = [] 
    972976        validator_list = [self.isValidPhone] + validator_list 
    973         TextField.__init__(self, field_name, length=12, maxlength=12, 
     977        TextField.__init__(self, field_name, length=12, max_length=12, 
    974978            is_required=is_required, validator_list=validator_list) 
    975979 
    976980    def isValidPhone(self, field_data, all_data): 
     
    984988    def __init__(self, field_name, is_required=False, validator_list=None): 
    985989        if validator_list is None: validator_list = [] 
    986990        validator_list = [self.isValidUSState] + validator_list 
    987         TextField.__init__(self, field_name, length=2, maxlength=2, 
     991        TextField.__init__(self, field_name, length=2, max_length=2, 
    988992            is_required=is_required, validator_list=validator_list) 
    989993 
    990994    def isValidUSState(self, field_data, all_data): 
     
    10011005 
    10021006class CommaSeparatedIntegerField(TextField): 
    10031007    "A convenience FormField for validating comma-separated integer fields" 
    1004     def __init__(self, field_name, maxlength=None, is_required=False, validator_list=None): 
     1008    def __init__(self, field_name, max_length=None, is_required=False, validator_list=None): 
    10051009        if validator_list is None: validator_list = [] 
    10061010        validator_list = [self.isCommaSeparatedIntegerList] + validator_list 
    1007         TextField.__init__(self, field_name, length=20, maxlength=maxlength, 
     1011        TextField.__init__(self, field_name, length=20, max_length=max_length, 
    10081012            is_required=is_required, validator_list=validator_list) 
    10091013 
    10101014    def isCommaSeparatedIntegerList(self, field_data, all_data): 
  • docs/contributing.txt

    old new  
    340340      Do this:: 
    341341 
    342342          class Person(models.Model): 
    343               first_name = models.CharField(maxlength=20) 
    344               last_name = models.CharField(maxlength=40) 
     343              first_name = models.CharField(max_length=20) 
     344              last_name = models.CharField(max_length=40) 
    345345 
    346346      Don't do this:: 
    347347 
    348348          class Person(models.Model): 
    349               FirstName = models.CharField(maxlength=20) 
    350               Last_Name = models.CharField(maxlength=40) 
     349              FirstName = models.CharField(max_length=20) 
     350              Last_Name = models.CharField(max_length=40) 
    351351 
    352352    * The ``class Meta`` should appear *after* the fields are defined, with 
    353353      a single blank line separating the fields and the class definition. 
     
    355355      Do this:: 
    356356 
    357357          class Person(models.Model): 
    358               first_name = models.CharField(maxlength=20) 
    359               last_name = models.CharField(maxlength=40) 
     358              first_name = models.CharField(max_length=20) 
     359              last_name = models.CharField(max_length=40) 
    360360 
    361361              class Meta: 
    362362                  verbose_name_plural = 'people' 
     
    364364      Don't do this:: 
    365365 
    366366          class Person(models.Model): 
    367               first_name = models.CharField(maxlength=20) 
    368               last_name = models.CharField(maxlength=40) 
     367              first_name = models.CharField(max_length=20) 
     368              last_name = models.CharField(max_length=40) 
    369369              class Meta: 
    370370                  verbose_name_plural = 'people' 
    371371 
     
    375375              class Meta: 
    376376                  verbose_name_plural = 'people' 
    377377 
    378               first_name = models.CharField(maxlength=20) 
    379               last_name = models.CharField(maxlength=40) 
     378              first_name = models.CharField(max_length=20) 
     379              last_name = models.CharField(max_length=40) 
    380380 
    381381    * The order of model inner classes and standard methods should be as 
    382382      follows (noting that these are not all required): 
  • docs/db-api.txt

    old new  
    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 __unicode__(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.EmailField() 
    2424 
    2525        def __unicode__(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) 
     
    18061806        ('F', 'Female'), 
    18071807    ) 
    18081808    class Person(models.Model): 
    1809         name = models.CharField(maxlength=20) 
    1810         gender = models.CharField(maxlength=1, choices=GENDER_CHOICES) 
     1809        name = models.CharField(max_length=20) 
     1810        gender = models.CharField(max_length=1, choices=GENDER_CHOICES) 
    18111811 
    18121812...each ``Person`` instance will have a ``get_gender_display()`` method. Example:: 
    18131813 
  • docs/forms.txt

    old new  
    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/model-api.txt

    old new  
    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 
     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 
    147147and in Django's validation. 
    148148 
    149 ``CommaSeparatedIntegerField`` 
     149Django veterans: Note that the argument is now called ``max_length`` to 
     150provide consistency throughout Django. There is full legacy support for 
     151the old ``maxlength`` argument, but ``max_length`` is prefered. 
     152         
     153 ``CommaSeparatedIntegerField`` 
    150154~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    151155 
    152 A field of integers separated by commas. As in ``CharField``, the ``maxlength`` 
     156A field of integers separated by commas. As in ``CharField``, the ``max_length`` 
    153157argument is required. 
    154158 
    155159``DateField`` 
     
    217221~~~~~~~~~~~~~~ 
    218222 
    219223A ``CharField`` that checks that the value is a valid e-mail address. 
    220 This doesn't accept ``maxlength``; its ``maxlength`` is automatically set to 
     224This doesn't accept ``max_length``; its ``max_length`` is automatically set to 
    22122575. 
    222226 
    223227``FileField`` 
     
    400404containing only letters, numbers, underscores or hyphens. They're generally 
    401405used in URLs. 
    402406 
    403 Like a CharField, you can specify ``maxlength``. If ``maxlength`` is 
     407Like a CharField, you can specify ``max_length``. If ``max_length`` is 
    404408not specified, Django will use a default length of 50. 
    405409 
    406410Implies ``db_index=True``. 
     
    447451 
    448452The admin represents this as an ``<input type="text">`` (a single-line input). 
    449453 
    450 ``URLField`` takes an optional argument, ``maxlength``, the maximum length (in 
    451 characters) of the field. The maxlength is enforced at the database level and 
    452 in Django's validation. If you don't specify ``maxlength``, a default of 200 
     454``URLField`` takes an optional argument, ``max_length``, the maximum length (in 
     455characters) of the field. The maximum length is enforced at the database level and 
     456in Django's validation. If you don't specify ``max_length``, a default of 200 
    453457is used. 
    454458 
    455459``USStateField`` 
     
    536540            ('M', 'Male'), 
    537541            ('F', 'Female'), 
    538542        ) 
    539         gender = models.CharField(maxlength=1, choices=GENDER_CHOICES) 
     543        gender = models.CharField(max_length=1, choices=GENDER_CHOICES) 
    540544 
    541545or outside your model class altogether:: 
    542546 
     
    545549        ('F', 'Female'), 
    546550    ) 
    547551    class Foo(models.Model): 
    548         gender = models.CharField(maxlength=1, choices=GENDER_CHOICES) 
     552        gender = models.CharField(max_length=1, choices=GENDER_CHOICES) 
    549553 
    550554For each model field that has ``choices`` set, Django will add a method to 
    551555retrieve the human-readable name for the field's current value. See 
     
    698702 
    699703In this example, the verbose name is ``"Person's first name"``:: 
    700704 
    701     first_name = models.CharField("Person's first name", maxlength=30) 
     705    first_name = models.CharField("Person's first name", max_length=30) 
    702706 
    703707In this example, the verbose name is ``"first name"``:: 
    704708 
    705     first_name = models.CharField(maxlength=30) 
     709    first_name = models.CharField(max_length=30) 
    706710 
    707711``ForeignKey``, ``ManyToManyField`` and ``OneToOneField`` require the first 
    708712argument to be a model class, so use the ``verbose_name`` keyword argument:: 
     
    10271031``Field`` type:: 
    10281032 
    10291033    class Person(models.Model): 
    1030         name = models.CharField(maxlength=80) 
    1031         gender = models.CharField(maxlength=1) 
     1034        name = models.CharField(max_length=80) 
     1035        gender = models.CharField(max_length=1) 
    10321036        something_else = MytypeField() 
    10331037 
    10341038If you aim to build a database-agnostic application, you should account for 
     
    10741078 
    10751079    # This is a much more flexible example. 
    10761080    class BetterCharField(models.Field): 
    1077         def __init__(self, maxlength, *args, **kwargs): 
    1078             self.maxlength = maxlength 
     1081        def __init__(self, max_length, *args, **kwargs): 
     1082            self.max_length = max_length 
    10791083            super(BetterCharField, self).__init__(*args, **kwargs) 
    10801084 
    10811085        def db_type(self): 
    1082             return 'char(%s)' % self.maxlength 
     1086            return 'char(%s)' % self.max_length 
    10831087 
    10841088    # In the model: 
    10851089    class MyModel(models.Model): 
     
    10961100Give your model metadata by using an inner ``class Meta``, like so:: 
    10971101 
    10981102    class Foo(models.Model): 
    1099         bar = models.CharField(maxlength=30) 
     1103        bar = models.CharField(max_length=30) 
    11001104 
    11011105        class Meta: 
    11021106            # ... 
     
    12701274inner ``"class Admin"``, like so:: 
    12711275 
    12721276    class Person(models.Model): 
    1273         first_name = models.CharField(maxlength=30) 
    1274         last_name = models.CharField(maxlength=30) 
     1277        first_name = models.CharField(max_length=30) 
     1278        last_name = models.CharField(max_length=30) 
    12751279 
    12761280        class Admin: 
    12771281            # Admin options go here 
     
    14301434      Here's a full example model:: 
    14311435 
    14321436          class Person(models.Model): 
    1433               name = models.CharField(maxlength=50) 
     1437              name = models.CharField(max_length=50) 
    14341438              birthday = models.DateField() 
    14351439 
    14361440              class Admin: 
     
    14471451      Here's a full example model:: 
    14481452 
    14491453          class Person(models.Model): 
    1450               first_name = models.CharField(maxlength=50) 
    1451               last_name = models.CharField(maxlength=50) 
    1452               color_code = models.CharField(maxlength=6) 
     1454              first_name = models.CharField(max_length=50) 
     1455              last_name = models.CharField(max_length=50) 
     1456              color_code = models.CharField(max_length=6) 
    14531457 
    14541458              class Admin: 
    14551459                  list_display = ('first_name', 'last_name', 'colored_name') 
     
    14651469      Here's a full example model:: 
    14661470 
    14671471          class Person(models.Model): 
    1468               first_name = models.CharField(maxlength=50) 
     1472              first_name = models.CharField(max_length=50) 
    14691473              birthday = models.DateField() 
    14701474 
    14711475              class Admin: 
     
    14931497      For example:: 
    14941498 
    14951499        class Person(models.Model): 
    1496             first_name = models.CharField(maxlength=50) 
    1497             color_code = models.CharField(maxlength=6) 
     1500            first_name = models.CharField(max_length=50) 
     1501            color_code = models.CharField(max_length=6) 
    14981502 
    14991503            class Admin: 
    15001504                list_display = ('first_name', 'colored_first_name') 
     
    17441748            return result_list 
    17451749 
    17461750    class OpinionPoll(models.Model): 
    1747         question = models.CharField(maxlength=200) 
     1751        question = models.CharField(max_length=200) 
    17481752        poll_date = models.DateField() 
    17491753        objects = PollManager() 
    17501754 
    17511755    class Response(models.Model): 
    17521756        poll = models.ForeignKey(Poll) 
    1753         person_name = models.CharField(maxlength=50) 
     1757        person_name = models.CharField(max_length=50) 
    17541758        response = models.TextField() 
    17551759 
    17561760With this example, you'd use ``OpinionPoll.objects.with_counts()`` to return 
     
    17661770example, using this model:: 
    17671771 
    17681772    class Book(models.Model): 
    1769         title = models.CharField(maxlength=100) 
    1770         author = models.CharField(maxlength=50) 
     1773        title = models.CharField(max_length=100) 
     1774        author = models.CharField(max_length=50) 
    17711775 
    17721776...the statement ``Book.objects.all()`` will return all books in the database. 
    17731777 
     
    17851789 
    17861790    # Then hook it into the Book model explicitly. 
    17871791    class Book(models.Model): 
    1788         title = models.CharField(maxlength=100) 
    1789         author = models.CharField(maxlength=50) 
     1792        title = models.CharField(max_length=100) 
     1793        author = models.CharField(max_length=50) 
    17901794 
    17911795        objects = models.Manager() # The default manager. 
    17921796        dahl_objects = DahlBookManager() # The Dahl-specific manager. 
     
    18191823            return super(FemaleManager, self).get_query_set().filter(sex='F') 
    18201824 
    18211825    class Person(models.Model): 
    1822         first_name = models.CharField(maxlength=50) 
    1823         last_name = models.CharField(maxlength=50) 
    1824         sex = models.CharField(maxlength=1, choices=(('M', 'Male'), ('F', 'Female'))) 
     1826        first_name = models.CharField(max_length=50) 
     1827        last_name = models.CharField(max_length=50) 
     1828        sex = models.CharField(max_length=1, choices=(('M', 'Male'), ('F', 'Female'))) 
    18251829        people = models.Manager() 
    18261830        men = MaleManager() 
    18271831        women = FemaleManager() 
     
    18511855For example, this model has a few custom methods:: 
    18521856 
    18531857    class Person(models.Model): 
    1854         first_name = models.CharField(maxlength=50) 
    1855         last_name = models.CharField(maxlength=50) 
     1858        first_name = models.CharField(max_length=50) 
     1859        last_name = models.CharField(max_length=50) 
    18561860        birth_date = models.DateField() 
    1857         address = models.CharField(maxlength=100) 
    1858         city = models.CharField(maxlength=50) 
     1861        address = models.CharField(max_length=100) 
     1862        city = models.CharField(max_length=50) 
    18591863        state = models.USStateField() # Yes, this is America-centric... 
    18601864 
    18611865        def baby_boomer_status(self): 
     
    18971901For example:: 
    18981902 
    18991903    class Person(models.Model): 
    1900         first_name = models.CharField(maxlength=50) 
    1901         last_name = models.CharField(maxlength=50) 
     1904        first_name = models.CharField(max_length=50) 
     1905        last_name = models.CharField(max_length=50) 
    19021906 
    19031907        def __str__(self): 
    19041908            # Note use of django.utils.encoding.smart_str() here because 
     
    19151919more simply as:: 
    19161920 
    19171921    class Person(models.Model): 
    1918         first_name = models.CharField(maxlength=50) 
    1919         last_name = models.CharField(maxlength=50) 
     1922        first_name = models.CharField(max_length=50) 
     1923        last_name = models.CharField(max_length=50) 
    19201924 
    19211925        def __unicode__(self): 
    19221926            return u'%s %s' % (self.first_name, self.last_name) 
     
    20582062to happen whenever you save an object. For example:: 
    20592063 
    20602064    class Blog(models.Model): 
    2061         name = models.CharField(maxlength=100) 
     2065        name = models.CharField(max_length=100) 
    20622066        tagline = models.TextField() 
    20632067 
    20642068        def save(self): 
     
    20692073You can also prevent saving:: 
    20702074 
    20712075    class Blog(models.Model): 
    2072         name = models.CharField(maxlength=100) 
     2076        name = models.CharField(max_length=100) 
    20732077        tagline = models.TextField() 
    20742078 
    20752079        def save(self): 
  • docs/newforms.txt

    old new  
    13721372    ``AutoField``                    Not represented in the form 
    13731373    ``BooleanField``                 ``BooleanField`` 
    13741374    ``CharField``                    ``CharField`` with ``max_length`` set to 
    1375                                      the model field's ``maxlength`` 
     1375                                     the model field's ``max_length`` 
    13761376    ``CommaSeparatedIntegerField``   ``CharField`` 
    13771377    ``DateField``                    ``DateField`` 
    13781378    ``DateTimeField``                ``DateTimeField`` 
     
    14521452    ) 
    14531453 
    14541454    class Author(models.Model): 
    1455         name = models.CharField(maxlength=100) 
    1456         title = models.CharField(maxlength=3, choices=TITLE_CHOICES) 
     1455        name = models.CharField(max_length=100) 
     1456        title = models.CharField(max_length=3, choices=TITLE_CHOICES) 
    14571457        birth_date = models.DateField(blank=True, null=True) 
    14581458 
    14591459        def __unicode__(self): 
    14601460            return self.name 
    14611461 
    14621462    class Book(models.Model): 
    1463         name = models.CharField(maxlength=100) 
     1463        name = models.CharField(max_length=100) 
    14641464        authors = models.ManyToManyField(Author) 
    14651465 
    14661466With these models, a call to ``form_for_model(Author)`` would return a ``Form`` 
  • docs/overview.txt

    old new  
    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 __unicode__(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/sites.txt

    old new  
    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() 
  • docs/testing.txt

    old new  
    7979        'The cat says "meow"' 
    8080        """ 
    8181 
    82         name = models.CharField(maxlength=20) 
    83         sound = models.CharField(maxlength=20) 
     82        name = models.CharField(max_length=20) 
     83        sound = models.CharField(max_length=20) 
    8484 
    8585        def speak(self): 
    8686            return 'The %s says "%s"' % (self.name, self.sound) 
  • docs/tutorial01.txt

    old new  
    251251    from django.db import models 
    252252 
    253253    class Poll(models.Model): 
    254         question = models.CharField(maxlength=200) 
     254        question = models.CharField(max_length=200) 
    255255        pub_date = models.DateTimeField('date published') 
    256256 
    257257    class Choice(models.Model): 
    258258        poll = models.ForeignKey(Poll) 
    259         choice = models.CharField(maxlength=200) 
     259        choice = models.CharField(max_length=200) 
    260260        votes = models.IntegerField() 
    261261 
    262262The code is straightforward. Each model is represented by a class that 
     
    279279machine-readable name will suffice as its human-readable name. 
    280280 
    281281Some ``Field`` classes have required elements. ``CharField``, for example, 
    282 requires that you give it a ``maxlength``. That's used not only in the database 
     282requires that you give it a ``max_length``. That's used not only in the database 
    283283schema, but in validation, as we'll soon see. 
    284284 
    285285Finally, note a relationship is defined, using ``models.ForeignKey``. That tells 
  • docs/tutorial02.txt

    old new  
    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' 
  • tests/modeltests/basic/models.py

    old new  
    88from django.db import models 
    99 
    1010class Article(models.Model): 
    11     headline = models.CharField(maxlength=100, default='Default headline') 
     11    headline = models.CharField(max_length=100, default='Default headline') 
    1212    pub_date = models.DateTimeField() 
    1313 
    1414    class Meta: 
  • tests/modeltests/choices/models.py

    old new  
    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 __unicode__(self): 
    2424        return self.name 
  • tests/modeltests/custom_columns/models.py

    old new  
    1818from django.db import models 
    1919 
    2020class Author(models.Model): 
    21     first_name = models.CharField(maxlength=30, db_column='firstname') 
    22     last_name = models.CharField(maxlength=30, db_column='last') 
     21    first_name = models.CharField(max_length=30, db_column='firstname') 
     22    last_name = models.CharField(max_length=30, db_column='last') 
    2323 
    2424    def __unicode__(self): 
    2525        return u'%s %s' % (self.first_name, self.last_name) 
     
    2929        ordering = ('last_name','first_name') 
    3030 
    3131class Article(models.Model): 
    32     headline = models.CharField(maxlength=100) 
     32    headline = models.CharField(max_length=100) 
    3333    authors = models.ManyToManyField(Author, db_table='my_m2m_table') 
    3434 
    3535    def __unicode__(self): 
  • tests/modeltests/custom_managers/models.py

    old new  
    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/custom_methods/models.py

    old new  
    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 __unicode__(self): 
  • tests/modeltests/custom_pk/models.py

    old new  
    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 u"%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/field_defaults/models.py

    old new  
    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 __unicode__(self): 
  • tests/modeltests/fixtures/models.py

    old new  
    1111from django.db import models 
    1212 
    1313class Article(models.Model): 
    14     headline = models.CharField(maxlength=100, default='Default headline') 
     14    headline = models.CharField(max_length=100, default='Default headline') 
    1515    pub_date = models.DateTimeField() 
    1616 
    1717    def __unicode__(self): 
  • tests/modeltests/generic_relations/models.py

    old new  
    2828        return self.tag 
    2929 
    3030class Animal(models.Model): 
    31     common_name = models.CharField(maxlength=150) 
    32     latin_name = models.CharField(maxlength=150) 
     31    common_name = models.CharField(max_length=150) 
     32    latin_name = models.CharField(max_length=150) 
    3333     
    3434    tags = generic.GenericRelation(TaggedItem) 
    3535 
     
    3737        return self.common_name 
    3838         
    3939class Vegetable(models.Model): 
    40     name = models.CharField(maxlength=150) 
     40    name = models.CharField(max_length=150) 
    4141    is_yucky = models.BooleanField(default=True) 
    4242     
    4343    tags = generic.GenericRelation(TaggedItem) 
     
    4646        return self.name 
    4747     
    4848class Mineral(models.Model): 
    49     name = models.CharField(maxlength=150) 
     49    name = models.CharField(max_length=150) 
    5050    hardness = models.PositiveSmallIntegerField() 
    5151     
    5252    # note the lack of an explicit GenericRelation here... 
  • tests/modeltests/get_latest/models.py

    old new  
    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/get_object_or_404/models.py

    old new  
    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 __unicode__(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/get_or_create/models.py

    old new  
    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 __unicode__(self): 
  • tests/modeltests/invalid_models/models.py

    old new  
    1010    charfield = models.CharField() 
    1111    decimalfield = models.DecimalField() 
    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. 
     
    100100class Model(models.Model): 
    101101    "But it's valid to call a model Model." 
    102102    year = models.PositiveIntegerField() #1960 
    103     make = models.CharField(maxlength=10) #Aston Martin 
    104     name = models.CharField(maxlength=10) #DB 4 GT 
     103    make = models.CharField(max_length=10) #Aston Martin 
     104    name = models.CharField(max_length=10) #DB 4 GT 
    105105 
    106106class Car(models.Model): 
    107     colour = models.CharField(maxlength=5) 
     107    colour = models.CharField(max_length=5) 
    108108    model = models.ForeignKey(Model) 
    109109 
    110 model_errors = """invalid_models.fielderrors: "charfield": CharFields require a "maxlength" attribute. 
     110model_errors = """invalid_models.fielderrors: "charfield": CharFields require a "max_length" attribute. 
    111111invalid_models.fielderrors: "decimalfield": DecimalFields require a "decimal_places" attribute. 
    112112invalid_models.fielderrors: "decimalfield": DecimalFields require a "max_digits" attribute. 
    113113invalid_models.fielderrors: "filefield": FileFields require an "upload_to" attribute. 
  • tests/modeltests/lookup/models.py

    old new  
    88from django.conf import settings 
    99 
    1010class Article(models.Model): 
    11     headline = models.CharField(maxlength=100) 
     11    headline = models.CharField(max_length=100) 
    1212    pub_date = models.DateTimeField() 
    1313    class Meta: 
    1414        ordering = ('-pub_date', 'headline') 
  • tests/modeltests/m2m_and_m2o/models.py

    old new  
    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/m2m_intermediary/models.py

    old new  
    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 __unicode__(self): 
    2020        return u"%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 __unicode__(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 __unicode__(self): 
    3535        return u'%s (%s)' % (self.reporter, self.position) 
  • tests/modeltests/m2m_multiple/models.py

    old new  
    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_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/m2o_recursive/models.py

    old new  
    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 __unicode__(self): 
  • tests/modeltests/m2o_recursive2/models.py

    old new  
    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/manipulators/models.py

    old new  
    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 __unicode__(self): 
    1414        return u"%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/modeltests/many_to_many/models.py

    old new  
    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 __unicode__(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 __unicode__(self): 
  • tests/modeltests/many_to_one/models.py

    old new  
    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 __unicode__(self): 
    1515        return u"%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/many_to_one_null/models.py

    old new  
    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 __unicode__(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/model_forms/models.py

    old new  
    3131) 
    3232 
    3333class Category(models.Model): 
    34     name = models.CharField(maxlength=20) 
    35     url = models.CharField('The URL', maxlength=40) 
     34    name = models.CharField(max_length=20) 
     35    url = models.CharField('The URL', max_length=40) 
    3636 
    3737    def __unicode__(self): 
    3838        return self.name 
    3939 
    4040class Writer(models.Model): 
    41     name = models.CharField(maxlength=50, help_text='Use both first and last names.') 
     41    name = models.CharField(max_length=50, help_text='Use both first and last names.') 
    4242 
    4343    def __unicode__(self): 
    4444        return self.name 
    4545 
    4646class Article(models.Model): 
    47     headline = models.CharField(maxlength=50) 
     47    headline = models.CharField(max_length=50) 
    4848    pub_date = models.DateField() 
    4949    created = models.DateField(editable=False) 
    5050    writer = models.ForeignKey(Writer) 
     
    6363 
    6464class PhoneNumber(models.Model): 
    6565    phone = models.PhoneNumberField() 
    66     description = models.CharField(maxlength=20) 
     66    description = models.CharField(max_length=20) 
    6767 
    6868    def __unicode__(self): 
    6969        return self.phone 
  • tests/modeltests/model_inheritance/models.py

    old new  
    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 __unicode__(self): 
    1414        return u"%s the place" % self.name 
  • tests/modeltests/mutually_referential/models.py

    old new  
    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/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 __unicode__(self): 
    1616        return u"%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 __unicode__(self): 
    3131        return u"%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/or_lookups/models.py

    old new  
    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/ordering/models.py

    old new  
    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/pagination/models.py

    old new  
    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 __unicode__(self): 
  • tests/modeltests/properties/models.py

    old new  
    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/reserved_names/models.py

    old new  
    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/reverse_lookup/models.py

    old new  
    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 __unicode__(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 __unicode__(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/save_delete_hooks/models.py

    old new  
    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 __unicode__(self): 
    1515        return u"%s %s" % (self.first_name, self.last_name) 
  • tests/modeltests/select_related/models.py

    old new  
    1212# Who remembers high school biology? 
    1313 
    1414class Domain(models.Model): 
    15     name = models.CharField(maxlength=50) 
     15    name = models.CharField(max_length=50) 
    1616    def __unicode__(self): 
    1717        return self.name 
    1818 
    1919class Kingdom(models.Model): 
    20     name = models.CharField(maxlength=50) 
     20    name = models.CharField(max_length=50) 
    2121    domain = models.ForeignKey(Domain) 
    2222    def __unicode__(self): 
    2323        return self.name 
    2424 
    2525class Phylum(models.Model): 
    26     name = models.CharField(maxlength=50) 
     26    name = models.CharField(max_length=50) 
    2727    kingdom = models.ForeignKey(Kingdom) 
    2828    def __unicode__(self): 
    2929        return self.name 
    3030     
    3131class Klass(models.Model): 
    32     name = models.CharField(maxlength=50) 
     32    name = models.CharField(max_length=50) 
    3333    phylum = models.ForeignKey(Phylum) 
    3434    def __unicode__(self): 
    3535        return self.name 
    3636     
    3737class Order(models.Model): 
    38     name = models.CharField(maxlength=50) 
     38    name = models.CharField(max_length=50) 
    3939    klass = models.ForeignKey(Klass) 
    4040    def __unicode__(self): 
    4141        return self.name 
    4242 
    4343class Family(models.Model): 
    44     name = models.CharField(maxlength=50) 
     44    name = models.CharField(max_length=50) 
    4545    order = models.ForeignKey(Order) 
    4646    def __unicode__(self): 
    4747        return self.name 
    4848 
    4949class Genus(models.Model): 
    50     name = models.CharField(maxlength=50) 
     50    name = models.CharField(max_length=50) 
    5151    family = models.ForeignKey(Family) 
    5252    def __unicode__(self): 
    5353        return self.name 
    5454 
    5555class Species(models.Model): 
    56     name = models.CharField(maxlength=50) 
     56    name = models.CharField(max_length=50) 
    5757    genus = models.ForeignKey(Genus) 
    5858    def __unicode__(self): 
    5959        return self.name 
  • tests/modeltests/serializers/models.py

    old new  
    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/str/models.py

    old new  
    1717from django.db import models 
    1818 
    1919class Article(models.Model): 
    20     headline = models.CharField(maxlength=100) 
     20    headline = models.CharField(max_length=100) 
    2121    pub_date = models.DateTimeField() 
    2222 
    2323    def __str__(self): 
     
    2626        return self.headline 
    2727 
    2828class InternationalArticle(models.Model): 
    29     headline = models.CharField(maxlength=100) 
     29    headline = models.CharField(max_length=100) 
    3030    pub_date = models.DateTimeField() 
    3131 
    3232    def __unicode__(self): 
  • tests/modeltests/transactions/models.py

    old new  
    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 __unicode__(self): 
  • tests/modeltests/validation/models.py

    old new  
    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/regressiontests/bug639/models.py

    old new  
    22from django.db import models 
    33 
    44class Photo(models.Model): 
    5     title = models.CharField(maxlength=30) 
     5    title = models.CharField(max_length=30) 
    66    image = models.FileField(upload_to=tempfile.gettempdir()) 
    77     
    88    # Support code for the tests; this keeps track of how many times save() gets 
  • tests/regressiontests/datatypes/models.py

    old new  
    77from django.conf import settings 
    88 
    99class Donut(models.Model): 
    10     name = models.CharField(maxlength=100) 
     10    name = models.CharField(max_length=100) 
    1111    is_frosted = models.BooleanField(default=False) 
    1212    has_sprinkles = models.NullBooleanField() 
    1313    baked_date = models.DateField(null=True) 
  • tests/regressiontests/fixtures_regress/models.py

    old new  
    22from django.contrib.auth.models import User 
    33 
    44class Animal(models.Model): 
    5     name = models.CharField(maxlength=150) 
    6     latin_name = models.CharField(maxlength=150) 
     5    name = models.CharField(max_length=150) 
     6    latin_name = models.CharField(max_length=150) 
    77 
    88    def __unicode__(self): 
    99        return self.common_name 
    1010 
    1111class Plant(models.Model): 
    12     name = models.CharField(maxlength=150) 
     12    name = models.CharField(max_length=150) 
    1313 
    1414    class Meta: 
    1515        # For testing when upper case letter in app name; regression for #4057 
    1616        db_table = "Fixtures_regress_plant" 
    1717 
    1818class Stuff(models.Model): 
    19     name = models.CharField(maxlength=20, null=True) 
     19    name = models.CharField(max_length=20, null=True) 
    2020    owner = models.ForeignKey(User, null=True) 
    2121     
    2222    def __unicode__(self): 
  • tests/regressiontests/initial_sql_regress/models.py

    old new  
    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/invalid_admin_options/models.py

    old new  
    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/many_to_one_regress/models.py

    old new  
    1212 
    1313# Protect against repetition of #1839, #2415 and #2536. 
    1414class Third(models.Model): 
    15     name = models.CharField(maxlength=20) 
     15    name = models.CharField(max_length=20) 
    1616    third = models.ForeignKey('self', null=True, related_name='child_set') 
    1717 
    1818class Parent(models.Model): 
    19     name = models.CharField(maxlength=20) 
     19    name = models.CharField(max_length=20) 
    2020    bestchild = models.ForeignKey('Child', null=True, related_name='favored_by') 
    2121 
    2222class Child(models.Model): 
    23     name = models.CharField(maxlength=20) 
     23    name = models.CharField(max_length=20) 
    2424    parent = models.ForeignKey(Parent) 
    2525 
    2626 
  • tests/regressiontests/model_regress/models.py

    old new  
    77) 
    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    status = models.IntegerField(blank=True, null=True, choices=CHOICES) 
    1313 
  • tests/regressiontests/null_queries/models.py

    old new  
    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 __unicode__(self): 
    77        return u"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 __unicode__(self): 
    1414        return u"Choice: %s in poll %s" % (self.choice, self.poll) 
  • tests/regressiontests/one_to_one_regress/models.py

    old new  
    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 __unicode__(self): 
    88        return u"%s the place" % self.name 
     
    1616        return u"%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 __unicode__(self): 
  • tests/regressiontests/serializers_regress/models.py

    old new  
    1616    data = models.BooleanField(null=True) 
    1717 
    1818class CharData(models.Model): 
    19     data = models.CharField(maxlength=30, null=True) 
     19    data = models.CharField(max_length=30, null=True) 
    2020 
    2121class DateData(models.Model): 
    2222    data = models.DateField(null=True) 
     
    9090        ordering = ["data"] 
    9191 
    9292class GenericData(models.Model): 
    93     data = models.CharField(maxlength=30) 
     93    data = models.CharField(max_length=30) 
    9494 
    9595    tags = generic.GenericRelation(Tag) 
    9696     
     
    102102    """This is a model that can be used as  
    103103    something for other models to point at""" 
    104104     
    105     data = models.CharField(maxlength=30) 
     105    data = models.CharField(max_length=30) 
    106106 
    107107class UniqueAnchor(models.Model): 
    108108    """This is a model that can be used as  
    109109    something for other models to point at""" 
    110110 
    111     data = models.CharField(unique=True, maxlength=30) 
     111    data = models.CharField(unique=True, max_length=30) 
    112112     
    113113class FKData(models.Model): 
    114114    data = models.ForeignKey(Anchor, null=True) 
     
    144144    data = models.BooleanField(primary_key=True) 
    145145     
    146146class CharPKData(models.Model): 
    147     data = models.CharField(maxlength=30, primary_key=True) 
     147    data = models.CharField(max_length=30, primary_key=True) 
    148148 
    149149# class DatePKData(models.Model): 
    150150#    data = models.DateField(primary_key=True) 
     
    208208#     data = models.XMLField(primary_key=True) 
    209209 
    210210class ComplexModel(models.Model): 
    211     field1 = models.CharField(maxlength=10) 
    212     field2 = models.CharField(maxlength=10) 
    213     field3 = models.CharField(maxlength=10) 
     211    field1 = models.CharField(max_length=10) 
     212    field2 = models.CharField(max_length=10) 
     213    field3 = models.CharField(max_length=10) 
    214214 
    215215# Tests for handling fields with pre_save functions, or 
    216216# models with save functions that modify data 
  • tests/regressiontests/string_lookup/models.py

    old new  
    22from django.db import models 
    33 
    44class Foo(models.Model): 
    5     name = models.CharField(maxlength=50) 
    6     friend = models.CharField(maxlength=50, blank=True) 
     5    name = models.CharField(max_length=50) 
     6    friend = models.CharField(max_length=50, blank=True) 
    77 
    88    def __unicode__(self): 
    99        return "Foo %s" % self.name 
    1010 
    1111class Bar(models.Model): 
    12     name = models.CharField(maxlength=50) 
     12    name = models.CharField(max_length=50) 
    1313    normal = models.ForeignKey(Foo, related_name='normal_foo') 
    1414    fwd = models.ForeignKey("Whiz") 
    1515    back = models.ForeignKey("Foo") 
     
    1818        return "Bar %s" % self.place.name 
    1919 
    2020class Whiz(models.Model): 
    21     name = models.CharField(maxlength = 50) 
     21    name = models.CharField(max_length = 50) 
    2222 
    2323    def __unicode__(self): 
    2424        return "Whiz %s" % self.name 
    2525 
    2626class Child(models.Model): 
    2727    parent = models.OneToOneField('Base') 
    28     name = models.CharField(maxlength = 50) 
     28    name = models.CharField(max_length = 50) 
    2929 
    3030    def __unicode__(self): 
    3131        return "Child %s" % self.name 
    3232 
    3333class Base(models.Model): 
    34     name = models.CharField(maxlength = 50) 
     34    name = models.CharField(max_length = 50) 
    3535 
    3636    def __unicode__(self): 
    3737        return "Base %s" % self.name