Ticket #2101: max_length.3.diff
File max_length.3.diff, 124.9 KB (added by , 17 years ago) |
---|
-
django/utils/maxlength.py
=== added file 'django/utils/maxlength.py'
1 """ 2 Methods and functions for legacy maxlength support. 3 """ 4 5 def get_maxlength(self): 6 return self.max_length 7 8 def set_maxlength(self, value): 9 self.max_length = value 10 11 def legacy_maxlength(max_length, maxlength, default=None): 12 """ 13 Provides backwards compatibilty for the legacy "maxlength" attribute. 14 If one of max_length or maxlength is given, then that value is returned. 15 If both are given, a TypeError is raised. 16 If neither are given, the default value or None is returned depending on 17 if a default value was given or not. 18 """ 19 if max_length is not None and maxlength is not None: 20 raise TypeError("field can not take both the max_length argument and" 21 " the legacy maxlength argument.") 22 for value in [max_length, maxlength, default]: 23 if value is not None: 24 return value 25 26 def legacy_maxlength_kwargs(kwargs, default=None): 27 """ 28 Similar to legacy_maxlength, but operates on a dictionary with max_length 29 and maxlength keys. The resulting maximum length is stored using the key 30 "max_length", and the "maxlength" key is removed it if exists. 31 """ 32 kwargs['max_length'] = legacy_maxlength(kwargs.get('max_length', None), 33 kwargs.get('maxlength', None), 34 default) 35 if 'maxlength' in kwargs: 36 del kwargs['maxlength'] 37 return kwargs -
tests/regressiontests/maxlength/tests.py
=== added directory 'tests/regressiontests/maxlength' === added file 'tests/regressiontests/maxlength/__init__.py' === added file 'tests/regressiontests/maxlength/models.py' === added file 'tests/regressiontests/maxlength/tests.py'
1 # Test access to max_length while still providing full backwards compatibility 2 # with legacy maxlength attribute. 3 """ 4 # legacy_maxlength 5 6 >>> from django.oldforms import legacy_maxlength 7 8 >>> legacy_maxlength(None, None) 9 10 11 >>> legacy_maxlength(10, None) 12 10 13 14 >>> legacy_maxlength(None, 10) 15 10 16 17 >>> legacy_maxlength(10, 12) 18 Traceback (most recent call last): 19 ... 20 TypeError: field can not take both the max_length argument and the legacy maxlength argument. 21 22 >>> legacy_maxlength(None, None, 50) 23 50 24 25 >>> legacy_maxlength(10, None, 50) 26 10 27 28 >>> legacy_maxlength(None, 10, 50) 29 10 30 31 >>> legacy_maxlength(10, 12, 50) 32 Traceback (most recent call last): 33 ... 34 TypeError: field can not take both the max_length argument and the legacy maxlength argument. 35 36 >>> legacy_maxlength(0, 10) 37 Traceback (most recent call last): 38 ... 39 TypeError: field can not take both the max_length argument and the legacy maxlength argument. 40 41 >>> legacy_maxlength(0, None, 10) 42 0 43 44 >>> legacy_maxlength(None, 0, 10) 45 0 46 47 #=============================================================================== 48 # Fields 49 #=============================================================================== 50 51 # Set up fields 52 >>> from django.db.models import fields 53 >>> new = fields.Field(max_length=15) 54 >>> old = fields.Field(maxlength=10) 55 56 # Ensure both max_length and legacy maxlength are not able to both be specified 57 >>> fields.Field(maxlength=10, max_length=15) 58 Traceback (most recent call last): 59 ... 60 TypeError: field can not take both the max_length argument and the legacy maxlength argument. 61 62 # Test max_length 63 >>> new.max_length 64 15 65 >>> old.max_length 66 10 67 68 # Test accessing maxlength 69 >>> new.maxlength 70 15 71 >>> old.maxlength 72 10 73 74 # Test setting maxlength 75 >>> new.maxlength += 1 76 >>> old.maxlength += 1 77 >>> new.max_length 78 16 79 >>> old.max_length 80 11 81 82 # SlugField __init__ passes through max_length so test that too 83 >>> fields.SlugField('new', max_length=15).max_length 84 15 85 >>> fields.SlugField('empty').max_length 86 50 87 >>> fields.SlugField('old', maxlength=10).max_length 88 10 89 90 #=============================================================================== 91 # (old)forms 92 #=============================================================================== 93 94 >>> from django import oldforms 95 96 # Test max_length attribute 97 98 >>> oldforms.TextField('new', max_length=15).render('') 99 u'<input type="text" id="id_new" class="vTextField" name="new" size="30" value="" maxlength="15" />' 100 101 >>> oldforms.IntegerField('new', max_length=15).render('') 102 u'<input type="text" id="id_new" class="vIntegerField" name="new" size="10" value="" maxlength="15" />' 103 104 >>> oldforms.SmallIntegerField('new', max_length=15).render('') 105 u'<input type="text" id="id_new" class="vSmallIntegerField" name="new" size="5" value="" maxlength="15" />' 106 107 >>> oldforms.PositiveIntegerField('new', max_length=15).render('') 108 u'<input type="text" id="id_new" class="vPositiveIntegerField" name="new" size="10" value="" maxlength="15" />' 109 110 >>> oldforms.PositiveSmallIntegerField('new', max_length=15).render('') 111 u'<input type="text" id="id_new" class="vPositiveSmallIntegerField" name="new" size="5" value="" maxlength="15" />' 112 113 >>> oldforms.DatetimeField('new', max_length=15).render('') 114 u'<input type="text" id="id_new" class="vDatetimeField" name="new" size="30" value="" maxlength="15" />' 115 116 >>> oldforms.EmailField('new', max_length=15).render('') 117 u'<input type="text" id="id_new" class="vEmailField" name="new" size="50" value="" maxlength="15" />' 118 >>> oldforms.EmailField('new').render('') 119 u'<input type="text" id="id_new" class="vEmailField" name="new" size="50" value="" maxlength="75" />' 120 121 >>> oldforms.URLField('new', max_length=15).render('') 122 u'<input type="text" id="id_new" class="vURLField" name="new" size="50" value="" maxlength="15" />' 123 >>> oldforms.URLField('new').render('') 124 u'<input type="text" id="id_new" class="vURLField" name="new" size="50" value="" maxlength="200" />' 125 126 >>> oldforms.IPAddressField('new', max_length=15).render('') 127 u'<input type="text" id="id_new" class="vIPAddressField" name="new" size="15" value="" maxlength="15" />' 128 >>> oldforms.IPAddressField('new').render('') 129 u'<input type="text" id="id_new" class="vIPAddressField" name="new" size="15" value="" maxlength="15" />' 130 131 >>> oldforms.CommaSeparatedIntegerField('new', max_length=15).render('') 132 u'<input type="text" id="id_new" class="vCommaSeparatedIntegerField" name="new" size="20" value="" maxlength="15" />' 133 134 135 # Test legacy maxlength attribute 136 137 >>> oldforms.TextField('old', maxlength=10).render('') 138 u'<input type="text" id="id_old" class="vTextField" name="old" size="30" value="" maxlength="10" />' 139 140 >>> oldforms.IntegerField('old', maxlength=10).render('') 141 u'<input type="text" id="id_old" class="vIntegerField" name="old" size="10" value="" maxlength="10" />' 142 143 >>> oldforms.SmallIntegerField('old', maxlength=10).render('') 144 u'<input type="text" id="id_old" class="vSmallIntegerField" name="old" size="5" value="" maxlength="10" />' 145 146 >>> oldforms.PositiveIntegerField('old', maxlength=10).render('') 147 u'<input type="text" id="id_old" class="vPositiveIntegerField" name="old" size="10" value="" maxlength="10" />' 148 149 >>> oldforms.PositiveSmallIntegerField('old', maxlength=10).render('') 150 u'<input type="text" id="id_old" class="vPositiveSmallIntegerField" name="old" size="5" value="" maxlength="10" />' 151 152 >>> oldforms.DatetimeField('old', maxlength=10).render('') 153 u'<input type="text" id="id_old" class="vDatetimeField" name="old" size="30" value="" maxlength="10" />' 154 155 >>> oldforms.EmailField('old', maxlength=10).render('') 156 u'<input type="text" id="id_old" class="vEmailField" name="old" size="50" value="" maxlength="10" />' 157 158 >>> oldforms.URLField('old', maxlength=10).render('') 159 u'<input type="text" id="id_old" class="vURLField" name="old" size="50" value="" maxlength="10" />' 160 161 >>> oldforms.IPAddressField('old', maxlength=10).render('') 162 u'<input type="text" id="id_old" class="vIPAddressField" name="old" size="15" value="" maxlength="10" />' 163 164 >>> oldforms.CommaSeparatedIntegerField('old', maxlength=10).render('') 165 u'<input type="text" id="id_old" class="vCommaSeparatedIntegerField" name="old" size="20" value="" maxlength="10" />' 166 """ 167 if __name__ == "__main__": 168 import doctest 169 doctest.testmod() -
django/contrib/admin/models.py
=== modified file 'django/contrib/admin/models.py'
18 18 user = models.ForeignKey(User) 19 19 content_type = models.ForeignKey(ContentType, blank=True, null=True) 20 20 object_id = models.TextField(_('object id'), blank=True, null=True) 21 object_repr = models.CharField(_('object repr'), max length=200)21 object_repr = models.CharField(_('object repr'), max_length=200) 22 22 action_flag = models.PositiveSmallIntegerField(_('action flag')) 23 23 change_message = models.TextField(_('change message'), blank=True) 24 24 objects = LogEntryManager() -
django/contrib/admin/templatetags/admin_modify.py
=== modified file 'django/contrib/admin/templatetags/admin_modify.py'
192 192 t.append(u'document.getElementById("id_%s").onkeyup = function() {' \ 193 193 ' var e = document.getElementById("id_%s");' \ 194 194 ' if(!e._changed) { e.value = URLify(%s, %s);} }; ' % ( 195 f, field.name, add_values, field.max length))195 f, field.name, add_values, field.max_length)) 196 196 return u''.join(t) 197 197 auto_populated_field_script = register.simple_tag(auto_populated_field_script) 198 198 -
django/contrib/admin/views/doc.py
=== modified file 'django/contrib/admin/views/doc.py'
291 291 DATA_TYPE_MAPPING = { 292 292 'AutoField' : _('Integer'), 293 293 'BooleanField' : _('Boolean (Either True or False)'), 294 'CharField' : _('String (up to %(max length)s)'),294 'CharField' : _('String (up to %(max_length)s)'), 295 295 'CommaSeparatedIntegerField': _('Comma-separated integers'), 296 296 'DateField' : _('Date (without time)'), 297 297 'DateTimeField' : _('Date (with time)'), … … 310 310 'PhoneNumberField' : _('Phone number'), 311 311 'PositiveIntegerField' : _('Integer'), 312 312 'PositiveSmallIntegerField' : _('Integer'), 313 'SlugField' : _('String (up to %(max length)s)'),313 'SlugField' : _('String (up to %(max_length)s)'), 314 314 'SmallIntegerField' : _('Integer'), 315 315 'TextField' : _('Text'), 316 316 'TimeField' : _('Time'), -
django/contrib/auth/forms.py
=== modified file 'django/contrib/auth/forms.py'
10 10 "A form that creates a user, with no privileges, from the given username and password." 11 11 def __init__(self): 12 12 self.fields = ( 13 oldforms.TextField(field_name='username', length=30, max length=30, is_required=True,13 oldforms.TextField(field_name='username', length=30, max_length=30, is_required=True, 14 14 validator_list=[validators.isAlphaNumeric, self.isValidUsername]), 15 oldforms.PasswordField(field_name='password1', length=30, max length=60, is_required=True),16 oldforms.PasswordField(field_name='password2', length=30, max length=60, is_required=True,15 oldforms.PasswordField(field_name='password1', length=30, max_length=60, is_required=True), 16 oldforms.PasswordField(field_name='password2', length=30, max_length=60, is_required=True, 17 17 validator_list=[validators.AlwaysMatchesOtherField('password1', _("The two password fields didn't match."))]), 18 18 ) 19 19 … … 42 42 """ 43 43 self.request = request 44 44 self.fields = [ 45 oldforms.TextField(field_name="username", length=15, max length=30, is_required=True,45 oldforms.TextField(field_name="username", length=15, max_length=30, is_required=True, 46 46 validator_list=[self.isValidUser, self.hasCookiesEnabled]), 47 oldforms.PasswordField(field_name="password", length=15, max length=30, is_required=True),47 oldforms.PasswordField(field_name="password", length=15, max_length=30, is_required=True), 48 48 ] 49 49 self.user_cache = None 50 50 … … 111 111 def __init__(self, user): 112 112 self.user = user 113 113 self.fields = ( 114 oldforms.PasswordField(field_name="old_password", length=30, max length=30, is_required=True,114 oldforms.PasswordField(field_name="old_password", length=30, max_length=30, is_required=True, 115 115 validator_list=[self.isValidOldPassword]), 116 oldforms.PasswordField(field_name="new_password1", length=30, max length=30, is_required=True,116 oldforms.PasswordField(field_name="new_password1", length=30, max_length=30, is_required=True, 117 117 validator_list=[validators.AlwaysMatchesOtherField('new_password2', _("The two 'new password' fields didn't match."))]), 118 oldforms.PasswordField(field_name="new_password2", length=30, max length=30, is_required=True),118 oldforms.PasswordField(field_name="new_password2", length=30, max_length=30, is_required=True), 119 119 ) 120 120 121 121 def isValidOldPassword(self, new_data, all_data): … … 133 133 def __init__(self, user): 134 134 self.user = user 135 135 self.fields = ( 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,136 oldforms.PasswordField(field_name='password1', length=30, max_length=60, is_required=True), 137 oldforms.PasswordField(field_name='password2', length=30, max_length=60, is_required=True, 138 138 validator_list=[validators.AlwaysMatchesOtherField('password1', _("The two password fields didn't match."))]), 139 139 ) 140 140 -
django/contrib/auth/models.py
=== modified file 'django/contrib/auth/models.py'
50 50 51 51 Three basic permissions -- add, change and delete -- are automatically created for each Django model. 52 52 """ 53 name = models.CharField(_('name'), max length=50)53 name = models.CharField(_('name'), max_length=50) 54 54 content_type = models.ForeignKey(ContentType) 55 codename = models.CharField(_('codename'), max length=100)55 codename = models.CharField(_('codename'), max_length=100) 56 56 57 57 class Meta: 58 58 verbose_name = _('permission') … … 70 70 71 71 Beyond permissions, groups are a convenient way to categorize users to apply some label, or extended functionality, to them. For example, you could create a group 'Special users', and you could write code that would do special things to those users -- such as giving them access to a members-only portion of your site, or sending them members-only e-mail messages. 72 72 """ 73 name = models.CharField(_('name'), max length=80, unique=True)73 name = models.CharField(_('name'), max_length=80, unique=True) 74 74 permissions = models.ManyToManyField(Permission, verbose_name=_('permissions'), blank=True, filter_interface=models.HORIZONTAL) 75 75 76 76 class Meta: … … 108 108 109 109 Username and password are required. Other fields are optional. 110 110 """ 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)111 username = models.CharField(_('username'), max_length=30, unique=True, validator_list=[validators.isAlphaNumeric], help_text=_("Required. 30 characters or fewer. Alphanumeric characters only (letters, digits and underscores).")) 112 first_name = models.CharField(_('first name'), max_length=30, blank=True) 113 last_name = models.CharField(_('last name'), max_length=30, blank=True) 114 114 email = models.EmailField(_('e-mail address'), blank=True) 115 password = models.CharField(_('password'), max length=128, help_text=_("Use '[algo]$[salt]$[hexdigest]' or use the <a href=\"password/\">change password form</a>."))115 password = models.CharField(_('password'), max_length=128, help_text=_("Use '[algo]$[salt]$[hexdigest]' or use the <a href=\"password/\">change password form</a>.")) 116 116 is_staff = models.BooleanField(_('staff status'), default=False, help_text=_("Designates whether the user can log into this admin site.")) 117 117 is_active = models.BooleanField(_('active'), default=True, help_text=_("Designates whether this user can log into the Django admin. Unselect this instead of deleting accounts.")) 118 118 is_superuser = models.BooleanField(_('superuser status'), default=False, help_text=_("Designates that this user has all permissions without explicitly assigning them.")) -
django/contrib/comments/models.py
=== modified file 'django/contrib/comments/models.py'
65 65 user = models.ForeignKey(User, raw_id_admin=True) 66 66 content_type = models.ForeignKey(ContentType) 67 67 object_id = models.IntegerField(_('object ID')) 68 headline = models.CharField(_('headline'), max length=255, blank=True)69 comment = models.TextField(_('comment'), max length=3000)68 headline = models.CharField(_('headline'), max_length=255, blank=True) 69 comment = models.TextField(_('comment'), max_length=3000) 70 70 rating1 = models.PositiveSmallIntegerField(_('rating #1'), blank=True, null=True) 71 71 rating2 = models.PositiveSmallIntegerField(_('rating #2'), blank=True, null=True) 72 72 rating3 = models.PositiveSmallIntegerField(_('rating #3'), blank=True, null=True) … … 164 164 # A FreeComment is a comment by a non-registered user. 165 165 content_type = models.ForeignKey(ContentType) 166 166 object_id = models.IntegerField(_('object ID')) 167 comment = models.TextField(_('comment'), max length=3000)168 person_name = models.CharField(_("person's name"), max length=50)167 comment = models.TextField(_('comment'), max_length=3000) 168 person_name = models.CharField(_("person's name"), max_length=50) 169 169 submit_date = models.DateTimeField(_('date/time submitted'), auto_now_add=True) 170 170 is_public = models.BooleanField(_('is public')) 171 171 ip_address = models.IPAddressField(_('ip address')) -
django/contrib/comments/views/comments.py
=== modified file 'django/contrib/comments/views/comments.py'
29 29 else: 30 30 return [] 31 31 self.fields.extend([ 32 oldforms.LargeTextField(field_name="comment", max length=3000, is_required=True,32 oldforms.LargeTextField(field_name="comment", max_length=3000, is_required=True, 33 33 validator_list=[self.hasNoProfanities]), 34 34 oldforms.RadioSelectField(field_name="rating1", choices=choices, 35 35 is_required=ratings_required and num_rating_choices > 0, … … 122 122 "Manipulator that handles public free (unregistered) comments" 123 123 def __init__(self): 124 124 self.fields = ( 125 oldforms.TextField(field_name="person_name", max length=50, is_required=True,125 oldforms.TextField(field_name="person_name", max_length=50, is_required=True, 126 126 validator_list=[self.hasNoProfanities]), 127 oldforms.LargeTextField(field_name="comment", max length=3000, is_required=True,127 oldforms.LargeTextField(field_name="comment", max_length=3000, is_required=True, 128 128 validator_list=[self.hasNoProfanities]), 129 129 ) 130 130 -
django/contrib/contenttypes/models.py
=== modified file 'django/contrib/contenttypes/models.py'
32 32 CONTENT_TYPE_CACHE = {} 33 33 34 34 class ContentType(models.Model): 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)35 name = models.CharField(max_length=100) 36 app_label = models.CharField(max_length=100) 37 model = models.CharField(_('python model class name'), max_length=100) 38 38 objects = ContentTypeManager() 39 39 class Meta: 40 40 verbose_name = _('content type') -
django/contrib/flatpages/models.py
=== modified file 'django/contrib/flatpages/models.py'
4 4 from django.utils.translation import ugettext_lazy as _ 5 5 6 6 class FlatPage(models.Model): 7 url = models.CharField(_('URL'), max length=100, validator_list=[validators.isAlphaNumericURL], db_index=True,7 url = models.CharField(_('URL'), max_length=100, validator_list=[validators.isAlphaNumericURL], db_index=True, 8 8 help_text=_("Example: '/about/contact/'. Make sure to have leading and trailing slashes.")) 9 title = models.CharField(_('title'), max length=200)9 title = models.CharField(_('title'), max_length=200) 10 10 content = models.TextField(_('content')) 11 11 enable_comments = models.BooleanField(_('enable comments')) 12 template_name = models.CharField(_('template name'), max length=70, blank=True,12 template_name = models.CharField(_('template name'), max_length=70, blank=True, 13 13 help_text=_("Example: 'flatpages/contact_page.html'. If this isn't provided, the system will use 'flatpages/default.html'.")) 14 14 registration_required = models.BooleanField(_('registration required'), help_text=_("If this is checked, only logged-in users will be able to view the page.")) 15 15 sites = models.ManyToManyField(Site) -
django/contrib/redirects/models.py
=== modified file 'django/contrib/redirects/models.py'
4 4 5 5 class Redirect(models.Model): 6 6 site = models.ForeignKey(Site, radio_admin=models.VERTICAL) 7 old_path = models.CharField(_('redirect from'), max length=200, db_index=True,7 old_path = models.CharField(_('redirect from'), max_length=200, db_index=True, 8 8 help_text=_("This should be an absolute path, excluding the domain name. Example: '/events/search/'.")) 9 new_path = models.CharField(_('redirect to'), max length=200, blank=True,9 new_path = models.CharField(_('redirect to'), max_length=200, blank=True, 10 10 help_text=_("This can be either an absolute path (as above) or a full URL starting with 'http://'.")) 11 11 12 12 class Meta: -
django/contrib/sessions/models.py
=== modified file 'django/contrib/sessions/models.py'
65 65 the sessions documentation that is shipped with Django (also available 66 66 on the Django website). 67 67 """ 68 session_key = models.CharField(_('session key'), max length=40, primary_key=True)68 session_key = models.CharField(_('session key'), max_length=40, primary_key=True) 69 69 session_data = models.TextField(_('session data')) 70 70 expire_date = models.DateTimeField(_('expire date')) 71 71 objects = SessionManager() -
django/contrib/sites/models.py
=== modified file 'django/contrib/sites/models.py'
12 12 return self.get(pk=sid) 13 13 14 14 class Site(models.Model): 15 domain = models.CharField(_('domain name'), max length=100)16 name = models.CharField(_('display name'), max length=50)15 domain = models.CharField(_('domain name'), max_length=100) 16 name = models.CharField(_('display name'), max_length=50) 17 17 objects = SiteManager() 18 18 class Meta: 19 19 db_table = 'django_site' -
django/core/management.py
=== modified file 'django/core/management.py'
910 910 field_type, new_params = field_type 911 911 extra_params.update(new_params) 912 912 913 # Add max length for all CharFields.913 # Add max_length for all CharFields. 914 914 if field_type == 'CharField' and row[3]: 915 extra_params['max length'] = row[3]915 extra_params['max_length'] = row[3] 916 916 917 917 if field_type == 'DecimalField': 918 918 extra_params['max_digits'] = row[4] … … 987 987 for f in opts.fields: 988 988 if f.name == 'id' and not f.primary_key and opts.pk.name == 'id': 989 989 e.add(opts, '"%s": You can\'t use "id" as a field name, because each model automatically gets an "id" field if none of the fields have primary_key=True. You need to either remove/rename your "id" field or add primary_key=True to a field.' % f.name) 990 if isinstance(f, models.CharField) and f.max length in (None, 0):991 e.add(opts, '"%s": CharFields require a "max length" attribute.' % f.name)990 if isinstance(f, models.CharField) and f.max_length in (None, 0): 991 e.add(opts, '"%s": CharFields require a "max_length" attribute.' % f.name) 992 992 if isinstance(f, models.DecimalField): 993 993 if f.decimal_places is None: 994 994 e.add(opts, '"%s": DecimalFields require a "decimal_places" attribute.' % f.name) … … 1013 1013 if f.db_index not in (None, True, False): 1014 1014 e.add(opts, '"%s": "db_index" should be either None, True or False.' % f.name) 1015 1015 1016 # Check that max length <= 255 if using older MySQL versions.1016 # Check that max_length <= 255 if using older MySQL versions. 1017 1017 if settings.DATABASE_ENGINE == 'mysql': 1018 1018 db_version = connection.get_server_version() 1019 if db_version < (5, 0, 3) and isinstance(f, (models.CharField, models.CommaSeparatedIntegerField, models.SlugField)) and f.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]])))1019 if db_version < (5, 0, 3) and isinstance(f, (models.CharField, models.CommaSeparatedIntegerField, models.SlugField)) and f.max_length > 255: 1020 e.add(opts, '"%s": %s cannot have a "max_length" greater than 255 when you are using a version of MySQL prior to 5.0.3 (you are using %s).' % (f.name, f.__class__.__name__, '.'.join([str(n) for n in db_version[:3]]))) 1021 1021 1022 1022 # Check to see if the related field will clash with any 1023 1023 # existing fields, m2m fields, m2m related objects or related objects … … 1252 1252 from django.db import backend, connection, transaction, models 1253 1253 fields = ( 1254 1254 # "key" is a reserved word in MySQL, so use "cache_key" instead. 1255 models.CharField(name='cache_key', max length=255, unique=True, primary_key=True),1255 models.CharField(name='cache_key', max_length=255, unique=True, primary_key=True), 1256 1256 models.TextField(name='value'), 1257 1257 models.DateTimeField(name='expires', db_index=True), 1258 1258 ) -
django/db/backends/ado_mssql/creation.py
=== modified file 'django/db/backends/ado_mssql/creation.py'
1 1 DATA_TYPES = { 2 2 'AutoField': 'int IDENTITY (1, 1)', 3 3 'BooleanField': 'bit', 4 'CharField': 'varchar(%(max length)s)',5 'CommaSeparatedIntegerField': 'varchar(%(max length)s)',4 'CharField': 'varchar(%(max_length)s)', 5 'CommaSeparatedIntegerField': 'varchar(%(max_length)s)', 6 6 'DateField': 'smalldatetime', 7 7 'DateTimeField': 'smalldatetime', 8 8 'DecimalField': 'numeric(%(max_digits)s, %(decimal_places)s)', … … 17 17 'PhoneNumberField': 'varchar(20)', 18 18 'PositiveIntegerField': 'int CONSTRAINT [CK_int_pos_%(column)s] CHECK ([%(column)s] > 0)', 19 19 'PositiveSmallIntegerField': 'smallint CONSTRAINT [CK_smallint_pos_%(column)s] CHECK ([%(column)s] > 0)', 20 'SlugField': 'varchar(%(max length)s)',20 'SlugField': 'varchar(%(max_length)s)', 21 21 'SmallIntegerField': 'smallint', 22 22 'TextField': 'text', 23 23 'TimeField': 'time', -
django/db/backends/mysql/creation.py
=== modified file 'django/db/backends/mysql/creation.py'
5 5 DATA_TYPES = { 6 6 'AutoField': 'integer AUTO_INCREMENT', 7 7 'BooleanField': 'bool', 8 'CharField': 'varchar(%(max length)s)',9 'CommaSeparatedIntegerField': 'varchar(%(max length)s)',8 'CharField': 'varchar(%(max_length)s)', 9 'CommaSeparatedIntegerField': 'varchar(%(max_length)s)', 10 10 'DateField': 'date', 11 11 'DateTimeField': 'datetime', 12 12 'DecimalField': 'numeric(%(max_digits)s, %(decimal_places)s)', … … 21 21 'PhoneNumberField': 'varchar(20)', 22 22 'PositiveIntegerField': 'integer UNSIGNED', 23 23 'PositiveSmallIntegerField': 'smallint UNSIGNED', 24 'SlugField': 'varchar(%(max length)s)',24 'SlugField': 'varchar(%(max_length)s)', 25 25 'SmallIntegerField': 'smallint', 26 26 'TextField': 'longtext', 27 27 'TimeField': 'time', -
django/db/backends/mysql_old/creation.py
=== modified file 'django/db/backends/mysql_old/creation.py'
5 5 DATA_TYPES = { 6 6 'AutoField': 'integer AUTO_INCREMENT', 7 7 'BooleanField': 'bool', 8 'CharField': 'varchar(%(max length)s)',9 'CommaSeparatedIntegerField': 'varchar(%(max length)s)',8 'CharField': 'varchar(%(max_length)s)', 9 'CommaSeparatedIntegerField': 'varchar(%(max_length)s)', 10 10 'DateField': 'date', 11 11 'DateTimeField': 'datetime', 12 12 'DecimalField': 'numeric(%(max_digits)s, %(decimal_places)s)', … … 21 21 'PhoneNumberField': 'varchar(20)', 22 22 'PositiveIntegerField': 'integer UNSIGNED', 23 23 'PositiveSmallIntegerField': 'smallint UNSIGNED', 24 'SlugField': 'varchar(%(max length)s)',24 'SlugField': 'varchar(%(max_length)s)', 25 25 'SmallIntegerField': 'smallint', 26 26 'TextField': 'longtext', 27 27 'TimeField': 'time', -
django/db/backends/oracle/creation.py
=== modified file 'django/db/backends/oracle/creation.py'
8 8 DATA_TYPES = { 9 9 'AutoField': 'NUMBER(11)', 10 10 'BooleanField': 'NUMBER(1) CHECK (%(column)s IN (0,1))', 11 'CharField': 'NVARCHAR2(%(max length)s)',12 'CommaSeparatedIntegerField': 'VARCHAR2(%(max length)s)',11 'CharField': 'NVARCHAR2(%(max_length)s)', 12 'CommaSeparatedIntegerField': 'VARCHAR2(%(max_length)s)', 13 13 'DateField': 'DATE', 14 14 'DateTimeField': 'TIMESTAMP', 15 15 'DecimalField': 'NUMBER(%(max_digits)s, %(decimal_places)s)', -
django/db/backends/postgresql/creation.py
=== modified file 'django/db/backends/postgresql/creation.py'
5 5 DATA_TYPES = { 6 6 'AutoField': 'serial', 7 7 'BooleanField': 'boolean', 8 'CharField': 'varchar(%(max length)s)',9 'CommaSeparatedIntegerField': 'varchar(%(max length)s)',8 'CharField': 'varchar(%(max_length)s)', 9 'CommaSeparatedIntegerField': 'varchar(%(max_length)s)', 10 10 'DateField': 'date', 11 11 'DateTimeField': 'timestamp with time zone', 12 12 'DecimalField': 'numeric(%(max_digits)s, %(decimal_places)s)', … … 21 21 'PhoneNumberField': 'varchar(20)', 22 22 'PositiveIntegerField': 'integer CHECK ("%(column)s" >= 0)', 23 23 'PositiveSmallIntegerField': 'smallint CHECK ("%(column)s" >= 0)', 24 'SlugField': 'varchar(%(max length)s)',24 'SlugField': 'varchar(%(max_length)s)', 25 25 'SmallIntegerField': 'smallint', 26 26 'TextField': 'text', 27 27 'TimeField': 'time', -
django/db/backends/sqlite3/creation.py
=== modified file 'django/db/backends/sqlite3/creation.py'
4 4 DATA_TYPES = { 5 5 'AutoField': 'integer', 6 6 'BooleanField': 'bool', 7 'CharField': 'varchar(%(max length)s)',8 'CommaSeparatedIntegerField': 'varchar(%(max length)s)',7 'CharField': 'varchar(%(max_length)s)', 8 'CommaSeparatedIntegerField': 'varchar(%(max_length)s)', 9 9 'DateField': 'date', 10 10 'DateTimeField': 'datetime', 11 11 'DecimalField': 'decimal', … … 20 20 'PhoneNumberField': 'varchar(20)', 21 21 'PositiveIntegerField': 'integer unsigned', 22 22 'PositiveSmallIntegerField': 'smallint unsigned', 23 'SlugField': 'varchar(%(max length)s)',23 'SlugField': 'varchar(%(max_length)s)', 24 24 'SmallIntegerField': 'smallint', 25 25 'TextField': 'text', 26 26 'TimeField': 'time', -
django/db/backends/sqlite3/introspection.py
=== modified file 'django/db/backends/sqlite3/introspection.py'
81 81 import re 82 82 m = re.search(r'^\s*(?:var)?char\s*\(\s*(\d+)\s*\)\s*$', key) 83 83 if m: 84 return ('CharField', {'max length': int(m.group(1))})84 return ('CharField', {'max_length': int(m.group(1))}) 85 85 raise KeyError 86 86 87 87 DATA_TYPES_REVERSE = FlexibleFieldLookupDict() -
django/db/models/fields/__init__.py
=== modified file 'django/db/models/fields/__init__.py'
11 11 from django.utils.text import capfirst 12 12 from django.utils.translation import ugettext_lazy, ugettext as _ 13 13 from django.utils.encoding import smart_unicode, force_unicode, smart_str 14 from django.utils.maxlength import get_maxlength, set_maxlength, legacy_maxlength, legacy_maxlength_kwargs 14 15 import datetime, os, time 15 16 try: 16 17 import decimal … … 72 73 creation_counter = 0 73 74 74 75 def __init__(self, verbose_name=None, name=None, primary_key=False, 75 max length=None, unique=False, blank=False, null=False, db_index=False,76 max_length=None, unique=False, blank=False, null=False, db_index=False, 76 77 core=False, rel=None, default=NOT_PROVIDED, editable=True, serialize=True, 77 78 prepopulate_from=None, unique_for_date=None, unique_for_month=None, 78 79 unique_for_year=None, validator_list=None, choices=None, radio_admin=None, 79 help_text='', db_column=None, db_tablespace=None ):80 help_text='', db_column=None, db_tablespace=None, maxlength=None): 80 81 self.name = name 81 82 self.verbose_name = verbose_name 82 83 self.primary_key = primary_key 83 self.maxlength, self.unique = maxlength, unique 84 # Fields now use max_length, but still support the legacy 85 # maxlength argument. 86 self.max_length = legacy_maxlength(max_length=max_length, 87 maxlength=maxlength) 88 self.unique = unique 84 89 self.blank, self.null = blank, null 85 90 # Oracle treats the empty string ('') as null, so coerce the null 86 91 # option whenever '' is a possible value. … … 106 111 self.creation_counter = Field.creation_counter 107 112 Field.creation_counter += 1 108 113 114 # Support accessing and setting to the legacy maxlength argument. 115 maxlength = property(get_maxlength, set_maxlength) 116 109 117 def __cmp__(self, other): 110 118 # This is needed because bisect does not take a comparison function. 111 119 return cmp(self.creation_counter, other.creation_counter) … … 244 252 245 253 def prepare_field_objs_and_params(self, manipulator, name_prefix): 246 254 params = {'validator_list': self.validator_list[:]} 247 if self.max length and not self.choices: # Don't give SelectFields a maxlength parameter.248 params['max length'] = self.maxlength255 if self.max_length and not self.choices: # Don't give SelectFields a max_length parameter. 256 params['max_length'] = self.max_length 249 257 250 258 if self.choices: 251 259 if self.radio_admin: … … 461 469 return smart_unicode(value) 462 470 463 471 def formfield(self, **kwargs): 464 defaults = {'max_length': self.max length}472 defaults = {'max_length': self.max_length} 465 473 defaults.update(kwargs) 466 474 return super(CharField, self).formfield(**defaults) 467 475 … … 670 678 671 679 class EmailField(CharField): 672 680 def __init__(self, *args, **kwargs): 673 kwargs['maxlength'] = 75 681 kwargs = legacy_maxlength_kwargs(kwargs) 682 kwargs['max_length'] = 75 674 683 CharField.__init__(self, *args, **kwargs) 675 684 676 685 def get_internal_type(self): … … 829 838 class IPAddressField(Field): 830 839 empty_strings_allowed = False 831 840 def __init__(self, *args, **kwargs): 832 kwargs['maxlength'] = 15 841 kwargs = legacy_maxlength_kwargs(kwargs) 842 kwargs['max_length'] = 15 833 843 Field.__init__(self, *args, **kwargs) 834 844 835 845 def get_manipulator_field_objs(self): … … 877 887 878 888 class SlugField(Field): 879 889 def __init__(self, *args, **kwargs): 880 kwargs ['maxlength'] = kwargs.get('maxlength',50)890 kwargs = legacy_maxlength_kwargs(kwargs, default=50) 881 891 kwargs.setdefault('validator_list', []).append(validators.isSlug) 882 892 # Set db_index=True unless it's been set manually. 883 893 if 'db_index' not in kwargs: … … 963 973 964 974 class URLField(CharField): 965 975 def __init__(self, verbose_name=None, name=None, verify_exists=True, **kwargs): 966 kwargs ['maxlength'] = kwargs.get('maxlength',200)976 kwargs = legacy_maxlength_kwargs(kwargs, default=200) 967 977 if verify_exists: 968 978 kwargs.setdefault('validator_list', []).append(validators.isExistingURL) 969 979 self.verify_exists = verify_exists -
django/newforms/fields.py
=== modified file 'django/newforms/fields.py'
120 120 121 121 def widget_attrs(self, widget): 122 122 if self.max_length is not None and isinstance(widget, (TextInput, PasswordInput)): 123 # The HTML attribute is maxlength, not max_length. 123 124 return {'maxlength': str(self.max_length)} 124 125 125 126 class IntegerField(Field): -
django/oldforms/__init__.py
=== modified file 'django/oldforms/__init__.py'
4 4 from django.conf import settings 5 5 from django.utils.translation import ugettext, ungettext 6 6 from django.utils.encoding import smart_unicode, force_unicode 7 from django.utils.maxlength import get_maxlength, set_maxlength, legacy_maxlength, legacy_maxlength_kwargs 7 8 8 9 FORM_FIELD_ID_PREFIX = 'id_' 9 10 … … 390 391 391 392 class TextField(FormField): 392 393 input_type = "text" 393 def __init__(self, field_name, length=30, maxlength=None, is_required=False, validator_list=None, member_name=None): 394 def __init__(self, field_name, length=30, max_length=None, 395 is_required=False, validator_list=None, member_name=None, 396 maxlength=None): 394 397 if validator_list is None: validator_list = [] 395 398 self.field_name = field_name 396 self.length, self.maxlength = length, maxlength 399 self.length = length 400 # Fields now use max_length, but still support the legacy 401 # maxlength argument. 402 self.max_length = legacy_maxlength(max_length, maxlength) 397 403 self.is_required = is_required 398 404 self.validator_list = [self.isValidLength, self.hasNoNewlines] + validator_list 399 405 if member_name != None: 400 406 self.member_name = member_name 401 407 408 # Support accessing and setting the legacy maxlength argument. 409 maxlength = property(get_maxlength, set_maxlength) 410 402 411 def isValidLength(self, data, form): 403 if data and self.max length and len(smart_unicode(data)) > self.maxlength:412 if data and self.max_length and len(smart_unicode(data)) > self.max_length: 404 413 raise validators.ValidationError, ungettext("Ensure your text is less than %s character.", 405 "Ensure your text is less than %s characters.", self.max length) % self.maxlength414 "Ensure your text is less than %s characters.", self.max_length) % self.max_length 406 415 407 416 def hasNoNewlines(self, data, form): 408 417 if data and '\n' in data: … … 411 420 def render(self, data): 412 421 if data is None: 413 422 data = u'' 414 max length = u''415 if self.max length:416 max length = u'maxlength="%s" ' % self.maxlength423 max_length = u'' 424 if self.max_length: 425 max_length = u'maxlength="%s" ' % self.max_length 417 426 return u'<input type="%s" id="%s" class="v%s%s" name="%s" size="%s" value="%s" %s/>' % \ 418 427 (self.input_type, self.get_id(), self.__class__.__name__, self.is_required and u' required' or '', 419 self.field_name, self.length, escape(data), max length)428 self.field_name, self.length, escape(data), max_length) 420 429 421 430 def html2python(data): 422 431 return data … … 426 435 input_type = "password" 427 436 428 437 class LargeTextField(TextField): 429 def __init__(self, field_name, rows=10, cols=40, is_required=False, validator_list=None, maxlength=None): 438 def __init__(self, field_name, rows=10, cols=40, is_required=False, 439 validator_list=None, max_length=None, maxlength=None): 440 max_length = legacy_maxlength(max_length, maxlength) 430 441 if validator_list is None: validator_list = [] 431 442 self.field_name = field_name 432 443 self.rows, self.cols, self.is_required = rows, cols, is_required 433 444 self.validator_list = validator_list[:] 434 if max length:445 if max_length: 435 446 self.validator_list.append(self.isValidLength) 436 self.max length = maxlength447 self.max_length = max_length 437 448 438 449 def render(self, data): 439 450 if data is None: … … 710 721 #################### 711 722 712 723 class IntegerField(TextField): 713 def __init__(self, field_name, length=10, maxlength=None, is_required=False, validator_list=None, member_name=None): 724 def __init__(self, field_name, length=10, max_length=None, 725 is_required=False, validator_list=None, member_name=None, 726 maxlength=None): 727 max_length = legacy_maxlength(max_length, maxlength) 714 728 if validator_list is None: validator_list = [] 715 729 validator_list = [self.isInteger] + validator_list 716 730 if member_name is not None: 717 731 self.member_name = member_name 718 TextField.__init__(self, field_name, length, max length, is_required, validator_list)732 TextField.__init__(self, field_name, length, max_length, is_required, validator_list) 719 733 720 734 def isInteger(self, field_data, all_data): 721 735 try: … … 730 744 html2python = staticmethod(html2python) 731 745 732 746 class SmallIntegerField(IntegerField): 733 def __init__(self, field_name, length=5, maxlength=5, is_required=False, validator_list=None): 747 def __init__(self, field_name, length=5, max_length=None, 748 is_required=False, validator_list=None, maxlength=None): 749 max_length = legacy_maxlength(max_length, maxlength, 5) 734 750 if validator_list is None: validator_list = [] 735 751 validator_list = [self.isSmallInteger] + validator_list 736 IntegerField.__init__(self, field_name, length, max length, is_required, validator_list)752 IntegerField.__init__(self, field_name, length, max_length, is_required, validator_list) 737 753 738 754 def isSmallInteger(self, field_data, all_data): 739 755 if not -32768 <= int(field_data) <= 32767: 740 756 raise validators.CriticalValidationError, ugettext("Enter a whole number between -32,768 and 32,767.") 741 757 742 758 class PositiveIntegerField(IntegerField): 743 def __init__(self, field_name, length=10, maxlength=None, is_required=False, validator_list=None): 759 def __init__(self, field_name, length=10, max_length=None, 760 is_required=False, validator_list=None, maxlength=None): 761 max_length = legacy_maxlength(max_length, maxlength) 744 762 if validator_list is None: validator_list = [] 745 763 validator_list = [self.isPositive] + validator_list 746 IntegerField.__init__(self, field_name, length, max length, is_required, validator_list)764 IntegerField.__init__(self, field_name, length, max_length, is_required, validator_list) 747 765 748 766 def isPositive(self, field_data, all_data): 749 767 if int(field_data) < 0: 750 768 raise validators.CriticalValidationError, ugettext("Enter a positive number.") 751 769 752 770 class PositiveSmallIntegerField(IntegerField): 753 def __init__(self, field_name, length=5, maxlength=None, is_required=False, validator_list=None): 771 def __init__(self, field_name, length=5, max_length=None, 772 is_required=False, validator_list=None, maxlength=None): 773 max_length = legacy_maxlength(max_length, maxlength) 754 774 if validator_list is None: validator_list = [] 755 775 validator_list = [self.isPositiveSmall] + validator_list 756 IntegerField.__init__(self, field_name, length, max length, is_required, validator_list)776 IntegerField.__init__(self, field_name, length, max_length, is_required, validator_list) 757 777 758 778 def isPositiveSmall(self, field_data, all_data): 759 779 if not 0 <= int(field_data) <= 32767: … … 806 826 class DatetimeField(TextField): 807 827 """A FormField that automatically converts its data to a datetime.datetime object. 808 828 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): 829 def __init__(self, field_name, length=30, max_length=None, 830 is_required=False, validator_list=None, maxlength=None): 831 max_length = legacy_maxlength(max_length, maxlength) 810 832 if validator_list is None: validator_list = [] 811 833 self.field_name = field_name 812 self.length, self.max length = length, maxlength834 self.length, self.max_length = length, max_length 813 835 self.is_required = is_required 814 836 self.validator_list = [validators.isValidANSIDatetime] + validator_list 815 837 … … 836 858 def __init__(self, field_name, is_required=False, validator_list=None): 837 859 if validator_list is None: validator_list = [] 838 860 validator_list = [self.isValidDate] + validator_list 839 TextField.__init__(self, field_name, length=10, max length=10,861 TextField.__init__(self, field_name, length=10, max_length=10, 840 862 is_required=is_required, validator_list=validator_list) 841 863 842 864 def isValidDate(self, field_data, all_data): … … 861 883 def __init__(self, field_name, is_required=False, validator_list=None): 862 884 if validator_list is None: validator_list = [] 863 885 validator_list = [self.isValidTime] + validator_list 864 TextField.__init__(self, field_name, length=8, max length=8,886 TextField.__init__(self, field_name, length=8, max_length=8, 865 887 is_required=is_required, validator_list=validator_list) 866 888 867 889 def isValidTime(self, field_data, all_data): … … 893 915 894 916 class EmailField(TextField): 895 917 "A convenience FormField for validating e-mail addresses" 896 def __init__(self, field_name, length=50, maxlength=75, is_required=False, validator_list=None): 918 def __init__(self, field_name, length=50, max_length=None, 919 is_required=False, validator_list=None, maxlength=None): 920 max_length = legacy_maxlength(max_length, maxlength, 75) 897 921 if validator_list is None: validator_list = [] 898 922 validator_list = [self.isValidEmail] + validator_list 899 TextField.__init__(self, field_name, length, max length=maxlength,923 TextField.__init__(self, field_name, length, max_length=max_length, 900 924 is_required=is_required, validator_list=validator_list) 901 925 902 926 def isValidEmail(self, field_data, all_data): … … 907 931 908 932 class URLField(TextField): 909 933 "A convenience FormField for validating URLs" 910 def __init__(self, field_name, length=50, maxlength=200, is_required=False, validator_list=None): 934 def __init__(self, field_name, length=50, max_length=None, 935 is_required=False, validator_list=None, maxlength=None): 936 max_length = legacy_maxlength(max_length, maxlength, 200) 911 937 if validator_list is None: validator_list = [] 912 938 validator_list = [self.isValidURL] + validator_list 913 TextField.__init__(self, field_name, length=length, max length=maxlength,939 TextField.__init__(self, field_name, length=length, max_length=max_length, 914 940 is_required=is_required, validator_list=validator_list) 915 941 916 942 def isValidURL(self, field_data, all_data): … … 920 946 raise validators.CriticalValidationError, e.messages 921 947 922 948 class IPAddressField(TextField): 923 def __init__(self, field_name, length=15, maxlength=15, is_required=False, validator_list=None): 949 def __init__(self, field_name, length=15, max_length=None, 950 is_required=False, validator_list=None, maxlength=None): 951 max_length = legacy_maxlength(max_length, maxlength, 15) 924 952 if validator_list is None: validator_list = [] 925 953 validator_list = [self.isValidIPAddress] + validator_list 926 TextField.__init__(self, field_name, length=length, max length=maxlength,954 TextField.__init__(self, field_name, length=length, max_length=max_length, 927 955 is_required=is_required, validator_list=validator_list) 928 956 929 957 def isValidIPAddress(self, field_data, all_data): … … 970 998 def __init__(self, field_name, is_required=False, validator_list=None): 971 999 if validator_list is None: validator_list = [] 972 1000 validator_list = [self.isValidPhone] + validator_list 973 TextField.__init__(self, field_name, length=12, max length=12,1001 TextField.__init__(self, field_name, length=12, max_length=12, 974 1002 is_required=is_required, validator_list=validator_list) 975 1003 976 1004 def isValidPhone(self, field_data, all_data): … … 984 1012 def __init__(self, field_name, is_required=False, validator_list=None): 985 1013 if validator_list is None: validator_list = [] 986 1014 validator_list = [self.isValidUSState] + validator_list 987 TextField.__init__(self, field_name, length=2, max length=2,1015 TextField.__init__(self, field_name, length=2, max_length=2, 988 1016 is_required=is_required, validator_list=validator_list) 989 1017 990 1018 def isValidUSState(self, field_data, all_data): … … 1001 1029 1002 1030 class CommaSeparatedIntegerField(TextField): 1003 1031 "A convenience FormField for validating comma-separated integer fields" 1004 def __init__(self, field_name, maxlength=None, is_required=False, validator_list=None): 1032 def __init__(self, field_name, max_length=None, is_required=False, 1033 validator_list=None, maxlength=None): 1034 max_length = legacy_maxlength(max_length, maxlength) 1005 1035 if validator_list is None: validator_list = [] 1006 1036 validator_list = [self.isCommaSeparatedIntegerList] + validator_list 1007 TextField.__init__(self, field_name, length=20, max length=maxlength,1037 TextField.__init__(self, field_name, length=20, max_length=max_length, 1008 1038 is_required=is_required, validator_list=validator_list) 1009 1039 1010 1040 def isCommaSeparatedIntegerList(self, field_data, all_data): -
docs/contributing.txt
=== modified file 'docs/contributing.txt'
340 340 Do this:: 341 341 342 342 class Person(models.Model): 343 first_name = models.CharField(max length=20)344 last_name = models.CharField(max length=40)343 first_name = models.CharField(max_length=20) 344 last_name = models.CharField(max_length=40) 345 345 346 346 Don't do this:: 347 347 348 348 class Person(models.Model): 349 FirstName = models.CharField(max length=20)350 Last_Name = models.CharField(max length=40)349 FirstName = models.CharField(max_length=20) 350 Last_Name = models.CharField(max_length=40) 351 351 352 352 * The ``class Meta`` should appear *after* the fields are defined, with 353 353 a single blank line separating the fields and the class definition. … … 355 355 Do this:: 356 356 357 357 class Person(models.Model): 358 first_name = models.CharField(max length=20)359 last_name = models.CharField(max length=40)358 first_name = models.CharField(max_length=20) 359 last_name = models.CharField(max_length=40) 360 360 361 361 class Meta: 362 362 verbose_name_plural = 'people' … … 364 364 Don't do this:: 365 365 366 366 class Person(models.Model): 367 first_name = models.CharField(max length=20)368 last_name = models.CharField(max length=40)367 first_name = models.CharField(max_length=20) 368 last_name = models.CharField(max_length=40) 369 369 class Meta: 370 370 verbose_name_plural = 'people' 371 371 … … 375 375 class Meta: 376 376 verbose_name_plural = 'people' 377 377 378 first_name = models.CharField(max length=20)379 last_name = models.CharField(max length=40)378 first_name = models.CharField(max_length=20) 379 last_name = models.CharField(max_length=40) 380 380 381 381 * The order of model inner classes and standard methods should be as 382 382 follows (noting that these are not all required): -
docs/db-api.txt
=== modified file 'docs/db-api.txt'
12 12 a weblog application:: 13 13 14 14 class Blog(models.Model): 15 name = models.CharField(max length=100)15 name = models.CharField(max_length=100) 16 16 tagline = models.TextField() 17 17 18 18 def __unicode__(self): 19 19 return self.name 20 20 21 21 class Author(models.Model): 22 name = models.CharField(max length=50)22 name = models.CharField(max_length=50) 23 23 email = models.URLField() 24 24 25 25 def __unicode__(self): … … 27 27 28 28 class Entry(models.Model): 29 29 blog = models.ForeignKey(Blog) 30 headline = models.CharField(max length=255)30 headline = models.CharField(max_length=255) 31 31 body_text = models.TextField() 32 32 pub_date = models.DateTimeField() 33 33 authors = models.ManyToManyField(Author) … … 1806 1806 ('F', 'Female'), 1807 1807 ) 1808 1808 class Person(models.Model): 1809 name = models.CharField(max length=20)1810 gender = models.CharField(max length=1, choices=GENDER_CHOICES)1809 name = models.CharField(max_length=20) 1810 gender = models.CharField(max_length=1, choices=GENDER_CHOICES) 1811 1811 1812 1812 ...each ``Person`` instance will have a ``get_gender_display()`` method. Example:: 1813 1813 -
docs/forms.txt
=== modified file 'docs/forms.txt'
37 37 ) 38 38 39 39 class Place(models.Model): 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)40 name = models.CharField(max_length=100) 41 address = models.CharField(max_length=100, blank=True) 42 city = models.CharField(max_length=50, blank=True) 43 43 state = models.USStateField() 44 zip_code = models.CharField(max length=5, blank=True)44 zip_code = models.CharField(max_length=5, blank=True) 45 45 place_type = models.IntegerField(choices=PLACE_TYPES) 46 46 47 47 class Admin: … … 388 388 def __init__(self): 389 389 self.fields = ( 390 390 forms.EmailField(field_name="from", is_required=True), 391 forms.TextField(field_name="subject", length=30, max length=200, is_required=True),391 forms.TextField(field_name="subject", length=30, max_length=200, is_required=True), 392 392 forms.SelectField(field_name="urgency", choices=urgency_choices), 393 393 forms.LargeTextField(field_name="contents", is_required=True), 394 394 ) -
docs/model-api.txt
=== modified file 'docs/model-api.txt'
33 33 from django.db import models 34 34 35 35 class Person(models.Model): 36 first_name = models.CharField(max length=30)37 last_name = models.CharField(max length=30)36 first_name = models.CharField(max_length=30) 37 last_name = models.CharField(max_length=30) 38 38 39 39 ``first_name`` and ``last_name`` are *fields* of the model. Each field is 40 40 specified as a class attribute, and each attribute maps to a database column. … … 69 69 Example:: 70 70 71 71 class Musician(models.Model): 72 first_name = models.CharField(max length=50)73 last_name = models.CharField(max length=50)74 instrument = models.CharField(max length=100)72 first_name = models.CharField(max_length=50) 73 last_name = models.CharField(max_length=50) 74 instrument = models.CharField(max_length=100) 75 75 76 76 class Album(models.Model): 77 77 artist = models.ForeignKey(Musician) 78 name = models.CharField(max length=100)78 name = models.CharField(max_length=100) 79 79 release_date = models.DateField() 80 80 num_stars = models.IntegerField() 81 81 … … 142 142 143 143 The admin represents this as an ``<input type="text">`` (a single-line input). 144 144 145 ``CharField`` has an extra required argument, ``max length``, the maximum length146 (in characters) of the field. The max length is enforced at the database level145 ``CharField`` has an extra required argument, ``max_length``, the maximum length 146 (in characters) of the field. The max_length is enforced at the database level 147 147 and in Django's validation. 148 148 149 ``CommaSeparatedIntegerField`` 149 Django veterans: Note that the argument is now called ``max_length`` to 150 provide consistency throughout Django. There is full legacy support for 151 the old ``maxlength`` argument, but ``max_length`` is prefered. 152 153 ``CommaSeparatedIntegerField`` 150 154 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 151 155 152 A field of integers separated by commas. As in ``CharField``, the ``max length``156 A field of integers separated by commas. As in ``CharField``, the ``max_length`` 153 157 argument is required. 154 158 155 159 ``DateField`` … … 217 221 ~~~~~~~~~~~~~~ 218 222 219 223 A ``CharField`` that checks that the value is a valid e-mail address. 220 This doesn't accept ``max length``; its ``maxlength`` is automatically set to224 This doesn't accept ``max_length``; its ``max_length`` is automatically set to 221 225 75. 222 226 223 227 ``FileField`` … … 400 404 containing only letters, numbers, underscores or hyphens. They're generally 401 405 used in URLs. 402 406 403 Like a CharField, you can specify ``max length``. If ``maxlength`` is407 Like a CharField, you can specify ``max_length``. If ``max_length`` is 404 408 not specified, Django will use a default length of 50. 405 409 406 410 Implies ``db_index=True``. … … 447 451 448 452 The admin represents this as an ``<input type="text">`` (a single-line input). 449 453 450 ``URLField`` takes an optional argument, ``max length``, the maximum length (in451 characters) of the field. The max length is enforced at the database level and452 in Django's validation. If you don't specify ``max length``, a default of 200454 ``URLField`` takes an optional argument, ``max_length``, the maximum length (in 455 characters) of the field. The maximum length is enforced at the database level and 456 in Django's validation. If you don't specify ``max_length``, a default of 200 453 457 is used. 454 458 455 459 ``USStateField`` … … 536 540 ('M', 'Male'), 537 541 ('F', 'Female'), 538 542 ) 539 gender = models.CharField(max length=1, choices=GENDER_CHOICES)543 gender = models.CharField(max_length=1, choices=GENDER_CHOICES) 540 544 541 545 or outside your model class altogether:: 542 546 … … 545 549 ('F', 'Female'), 546 550 ) 547 551 class Foo(models.Model): 548 gender = models.CharField(max length=1, choices=GENDER_CHOICES)552 gender = models.CharField(max_length=1, choices=GENDER_CHOICES) 549 553 550 554 For each model field that has ``choices`` set, Django will add a method to 551 555 retrieve the human-readable name for the field's current value. See … … 698 702 699 703 In this example, the verbose name is ``"Person's first name"``:: 700 704 701 first_name = models.CharField("Person's first name", max length=30)705 first_name = models.CharField("Person's first name", max_length=30) 702 706 703 707 In this example, the verbose name is ``"first name"``:: 704 708 705 first_name = models.CharField(max length=30)709 first_name = models.CharField(max_length=30) 706 710 707 711 ``ForeignKey``, ``ManyToManyField`` and ``OneToOneField`` require the first 708 712 argument to be a model class, so use the ``verbose_name`` keyword argument:: … … 1027 1031 ``Field`` type:: 1028 1032 1029 1033 class Person(models.Model): 1030 name = models.CharField(max length=80)1031 gender = models.CharField(max length=1)1034 name = models.CharField(max_length=80) 1035 gender = models.CharField(max_length=1) 1032 1036 something_else = MytypeField() 1033 1037 1034 1038 If you aim to build a database-agnostic application, you should account for … … 1074 1078 1075 1079 # This is a much more flexible example. 1076 1080 class BetterCharField(models.Field): 1077 def __init__(self, max length, *args, **kwargs):1078 self.max length = maxlength1081 def __init__(self, max_length, *args, **kwargs): 1082 self.max_length = max_length 1079 1083 super(BetterCharField, self).__init__(*args, **kwargs) 1080 1084 1081 1085 def db_type(self): 1082 return 'char(%s)' % self.max length1086 return 'char(%s)' % self.max_length 1083 1087 1084 1088 # In the model: 1085 1089 class MyModel(models.Model): … … 1096 1100 Give your model metadata by using an inner ``class Meta``, like so:: 1097 1101 1098 1102 class Foo(models.Model): 1099 bar = models.CharField(max length=30)1103 bar = models.CharField(max_length=30) 1100 1104 1101 1105 class Meta: 1102 1106 # ... … … 1270 1274 inner ``"class Admin"``, like so:: 1271 1275 1272 1276 class Person(models.Model): 1273 first_name = models.CharField(max length=30)1274 last_name = models.CharField(max length=30)1277 first_name = models.CharField(max_length=30) 1278 last_name = models.CharField(max_length=30) 1275 1279 1276 1280 class Admin: 1277 1281 # Admin options go here … … 1430 1434 Here's a full example model:: 1431 1435 1432 1436 class Person(models.Model): 1433 name = models.CharField(max length=50)1437 name = models.CharField(max_length=50) 1434 1438 birthday = models.DateField() 1435 1439 1436 1440 class Admin: … … 1447 1451 Here's a full example model:: 1448 1452 1449 1453 class Person(models.Model): 1450 first_name = models.CharField(max length=50)1451 last_name = models.CharField(max length=50)1452 color_code = models.CharField(max length=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) 1453 1457 1454 1458 class Admin: 1455 1459 list_display = ('first_name', 'last_name', 'colored_name') … … 1465 1469 Here's a full example model:: 1466 1470 1467 1471 class Person(models.Model): 1468 first_name = models.CharField(max length=50)1472 first_name = models.CharField(max_length=50) 1469 1473 birthday = models.DateField() 1470 1474 1471 1475 class Admin: … … 1493 1497 For example:: 1494 1498 1495 1499 class Person(models.Model): 1496 first_name = models.CharField(max length=50)1497 color_code = models.CharField(max length=6)1500 first_name = models.CharField(max_length=50) 1501 color_code = models.CharField(max_length=6) 1498 1502 1499 1503 class Admin: 1500 1504 list_display = ('first_name', 'colored_first_name') … … 1744 1748 return result_list 1745 1749 1746 1750 class OpinionPoll(models.Model): 1747 question = models.CharField(max length=200)1751 question = models.CharField(max_length=200) 1748 1752 poll_date = models.DateField() 1749 1753 objects = PollManager() 1750 1754 1751 1755 class Response(models.Model): 1752 1756 poll = models.ForeignKey(Poll) 1753 person_name = models.CharField(max length=50)1757 person_name = models.CharField(max_length=50) 1754 1758 response = models.TextField() 1755 1759 1756 1760 With this example, you'd use ``OpinionPoll.objects.with_counts()`` to return … … 1766 1770 example, using this model:: 1767 1771 1768 1772 class Book(models.Model): 1769 title = models.CharField(max length=100)1770 author = models.CharField(max length=50)1773 title = models.CharField(max_length=100) 1774 author = models.CharField(max_length=50) 1771 1775 1772 1776 ...the statement ``Book.objects.all()`` will return all books in the database. 1773 1777 … … 1785 1789 1786 1790 # Then hook it into the Book model explicitly. 1787 1791 class Book(models.Model): 1788 title = models.CharField(max length=100)1789 author = models.CharField(max length=50)1792 title = models.CharField(max_length=100) 1793 author = models.CharField(max_length=50) 1790 1794 1791 1795 objects = models.Manager() # The default manager. 1792 1796 dahl_objects = DahlBookManager() # The Dahl-specific manager. … … 1819 1823 return super(FemaleManager, self).get_query_set().filter(sex='F') 1820 1824 1821 1825 class Person(models.Model): 1822 first_name = models.CharField(max length=50)1823 last_name = models.CharField(max length=50)1824 sex = models.CharField(max length=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'))) 1825 1829 people = models.Manager() 1826 1830 men = MaleManager() 1827 1831 women = FemaleManager() … … 1851 1855 For example, this model has a few custom methods:: 1852 1856 1853 1857 class Person(models.Model): 1854 first_name = models.CharField(max length=50)1855 last_name = models.CharField(max length=50)1858 first_name = models.CharField(max_length=50) 1859 last_name = models.CharField(max_length=50) 1856 1860 birth_date = models.DateField() 1857 address = models.CharField(max length=100)1858 city = models.CharField(max length=50)1861 address = models.CharField(max_length=100) 1862 city = models.CharField(max_length=50) 1859 1863 state = models.USStateField() # Yes, this is America-centric... 1860 1864 1861 1865 def baby_boomer_status(self): … … 1897 1901 For example:: 1898 1902 1899 1903 class Person(models.Model): 1900 first_name = models.CharField(max length=50)1901 last_name = models.CharField(max length=50)1904 first_name = models.CharField(max_length=50) 1905 last_name = models.CharField(max_length=50) 1902 1906 1903 1907 def __str__(self): 1904 1908 # Note use of django.utils.encoding.smart_str() here because … … 1915 1919 more simply as:: 1916 1920 1917 1921 class Person(models.Model): 1918 first_name = models.CharField(max length=50)1919 last_name = models.CharField(max length=50)1922 first_name = models.CharField(max_length=50) 1923 last_name = models.CharField(max_length=50) 1920 1924 1921 1925 def __unicode__(self): 1922 1926 return u'%s %s' % (self.first_name, self.last_name) … … 2056 2060 to happen whenever you save an object. For example:: 2057 2061 2058 2062 class Blog(models.Model): 2059 name = models.CharField(max length=100)2063 name = models.CharField(max_length=100) 2060 2064 tagline = models.TextField() 2061 2065 2062 2066 def save(self): … … 2067 2071 You can also prevent saving:: 2068 2072 2069 2073 class Blog(models.Model): 2070 name = models.CharField(max length=100)2074 name = models.CharField(max_length=100) 2071 2075 tagline = models.TextField() 2072 2076 2073 2077 def save(self): -
docs/newforms.txt
=== modified file 'docs/newforms.txt'
1372 1372 ``AutoField`` Not represented in the form 1373 1373 ``BooleanField`` ``BooleanField`` 1374 1374 ``CharField`` ``CharField`` with ``max_length`` set to 1375 the model field's ``max length``1375 the model field's ``max_length`` 1376 1376 ``CommaSeparatedIntegerField`` ``CharField`` 1377 1377 ``DateField`` ``DateField`` 1378 1378 ``DateTimeField`` ``DateTimeField`` … … 1452 1452 ) 1453 1453 1454 1454 class Author(models.Model): 1455 name = models.CharField(max length=100)1456 title = models.CharField(max length=3, choices=TITLE_CHOICES)1455 name = models.CharField(max_length=100) 1456 title = models.CharField(max_length=3, choices=TITLE_CHOICES) 1457 1457 birth_date = models.DateField(blank=True, null=True) 1458 1458 1459 1459 def __unicode__(self): 1460 1460 return self.name 1461 1461 1462 1462 class Book(models.Model): 1463 name = models.CharField(max length=100)1463 name = models.CharField(max_length=100) 1464 1464 authors = models.ManyToManyField(Author) 1465 1465 1466 1466 With these models, a call to ``form_for_model(Author)`` would return a ``Form`` -
docs/overview.txt
=== modified file 'docs/overview.txt'
25 25 quick example:: 26 26 27 27 class Reporter(models.Model): 28 full_name = models.CharField(max length=70)28 full_name = models.CharField(max_length=70) 29 29 30 30 def __unicode__(self): 31 31 return self.full_name 32 32 33 33 class Article(models.Model): 34 34 pub_date = models.DateTimeField() 35 headline = models.CharField(max length=200)35 headline = models.CharField(max_length=200) 36 36 article = models.TextField() 37 37 reporter = models.ForeignKey(Reporter) 38 38 … … 134 134 135 135 class Article(models.Model): 136 136 pub_date = models.DateTimeField() 137 headline = models.CharField(max length=200)137 headline = models.CharField(max_length=200) 138 138 article = models.TextField() 139 139 reporter = models.ForeignKey(Reporter) 140 140 class Admin: pass -
docs/sites.txt
=== modified file 'docs/sites.txt'
46 46 from django.contrib.sites.models import Site 47 47 48 48 class Article(models.Model): 49 headline = models.CharField(max length=200)49 headline = models.CharField(max_length=200) 50 50 # ... 51 51 sites = models.ManyToManyField(Site) 52 52 … … 87 87 from django.contrib.sites.models import Site 88 88 89 89 class Article(models.Model): 90 headline = models.CharField(max length=200)90 headline = models.CharField(max_length=200) 91 91 # ... 92 92 site = models.ForeignKey(Site) 93 93 … … 229 229 230 230 class Photo(models.Model): 231 231 photo = models.FileField(upload_to='/home/photos') 232 photographer_name = models.CharField(max length=100)232 photographer_name = models.CharField(max_length=100) 233 233 pub_date = models.DateField() 234 234 site = models.ForeignKey(Site) 235 235 objects = models.Manager() … … 257 257 258 258 class Photo(models.Model): 259 259 photo = models.FileField(upload_to='/home/photos') 260 photographer_name = models.CharField(max length=100)260 photographer_name = models.CharField(max_length=100) 261 261 pub_date = models.DateField() 262 262 publish_on = models.ForeignKey(Site) 263 263 objects = models.Manager() -
docs/testing.txt
=== modified file 'docs/testing.txt'
79 79 'The cat says "meow"' 80 80 """ 81 81 82 name = models.CharField(max length=20)83 sound = models.CharField(max length=20)82 name = models.CharField(max_length=20) 83 sound = models.CharField(max_length=20) 84 84 85 85 def speak(self): 86 86 return 'The %s says "%s"' % (self.name, self.sound) -
docs/tutorial01.txt
=== modified file 'docs/tutorial01.txt'
251 251 from django.db import models 252 252 253 253 class Poll(models.Model): 254 question = models.CharField(max length=200)254 question = models.CharField(max_length=200) 255 255 pub_date = models.DateTimeField('date published') 256 256 257 257 class Choice(models.Model): 258 258 poll = models.ForeignKey(Poll) 259 choice = models.CharField(max length=200)259 choice = models.CharField(max_length=200) 260 260 votes = models.IntegerField() 261 261 262 262 The code is straightforward. Each model is represented by a class that … … 279 279 machine-readable name will suffice as its human-readable name. 280 280 281 281 Some ``Field`` classes have required elements. ``CharField``, for example, 282 requires that you give it a ``max length``. That's used not only in the database282 requires that you give it a ``max_length``. That's used not only in the database 283 283 schema, but in validation, as we'll soon see. 284 284 285 285 Finally, note a relationship is defined, using ``models.ForeignKey``. That tells -
docs/tutorial02.txt
=== modified file 'docs/tutorial02.txt'
240 240 241 241 Then change the other fields in ``Choice`` to give them ``core=True``:: 242 242 243 choice = models.CharField(max length=200, core=True)243 choice = models.CharField(max_length=200, core=True) 244 244 votes = models.IntegerField(core=True) 245 245 246 246 This tells Django: "When you edit a Choice on the Poll admin page, the 'choice' -
tests/modeltests/basic/models.py
=== modified file 'tests/modeltests/basic/models.py'
8 8 from django.db import models 9 9 10 10 class Article(models.Model): 11 headline = models.CharField(max length=100, default='Default headline')11 headline = models.CharField(max_length=100, default='Default headline') 12 12 pub_date = models.DateTimeField() 13 13 14 14 class Meta: -
tests/modeltests/choices/models.py
=== modified file 'tests/modeltests/choices/models.py'
17 17 ) 18 18 19 19 class Person(models.Model): 20 name = models.CharField(max length=20)21 gender = models.CharField(max length=1, choices=GENDER_CHOICES)20 name = models.CharField(max_length=20) 21 gender = models.CharField(max_length=1, choices=GENDER_CHOICES) 22 22 23 23 def __unicode__(self): 24 24 return self.name -
tests/modeltests/custom_columns/models.py
=== modified file 'tests/modeltests/custom_columns/models.py'
18 18 from django.db import models 19 19 20 20 class Author(models.Model): 21 first_name = models.CharField(max length=30, db_column='firstname')22 last_name = models.CharField(max length=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') 23 23 24 24 def __unicode__(self): 25 25 return u'%s %s' % (self.first_name, self.last_name) … … 29 29 ordering = ('last_name','first_name') 30 30 31 31 class Article(models.Model): 32 headline = models.CharField(max length=100)32 headline = models.CharField(max_length=100) 33 33 authors = models.ManyToManyField(Author, db_table='my_m2m_table') 34 34 35 35 def __unicode__(self): -
tests/modeltests/custom_managers/models.py
=== modified file 'tests/modeltests/custom_managers/models.py'
18 18 return self.filter(fun=True) 19 19 20 20 class Person(models.Model): 21 first_name = models.CharField(max length=30)22 last_name = models.CharField(max length=30)21 first_name = models.CharField(max_length=30) 22 last_name = models.CharField(max_length=30) 23 23 fun = models.BooleanField() 24 24 objects = PersonManager() 25 25 … … 33 33 return super(PublishedBookManager, self).get_query_set().filter(is_published=True) 34 34 35 35 class Book(models.Model): 36 title = models.CharField(max length=50)37 author = models.CharField(max length=30)36 title = models.CharField(max_length=50) 37 author = models.CharField(max_length=30) 38 38 is_published = models.BooleanField() 39 39 published_objects = PublishedBookManager() 40 40 authors = models.ManyToManyField(Person, related_name='books') … … 49 49 return super(FastCarManager, self).get_query_set().filter(top_speed__gt=150) 50 50 51 51 class Car(models.Model): 52 name = models.CharField(max length=10)52 name = models.CharField(max_length=10) 53 53 mileage = models.IntegerField() 54 54 top_speed = models.IntegerField(help_text="In miles per hour.") 55 55 cars = models.Manager() -
tests/modeltests/custom_methods/models.py
=== modified file 'tests/modeltests/custom_methods/models.py'
8 8 import datetime 9 9 10 10 class Article(models.Model): 11 headline = models.CharField(max length=100)11 headline = models.CharField(max_length=100) 12 12 pub_date = models.DateField() 13 13 14 14 def __unicode__(self): -
tests/modeltests/custom_pk/models.py
=== modified file 'tests/modeltests/custom_pk/models.py'
8 8 from django.db import models 9 9 10 10 class Employee(models.Model): 11 employee_code = models.CharField(max length=10, primary_key=True,11 employee_code = models.CharField(max_length=10, primary_key=True, 12 12 db_column = 'code') 13 first_name = models.CharField(max length=20)14 last_name = models.CharField(max length=20)13 first_name = models.CharField(max_length=20) 14 last_name = models.CharField(max_length=20) 15 15 class Meta: 16 16 ordering = ('last_name', 'first_name') 17 17 … … 19 19 return u"%s %s" % (self.first_name, self.last_name) 20 20 21 21 class Business(models.Model): 22 name = models.CharField(max length=20, primary_key=True)22 name = models.CharField(max_length=20, primary_key=True) 23 23 employees = models.ManyToManyField(Employee) 24 24 class Meta: 25 25 verbose_name_plural = 'businesses' -
tests/modeltests/field_defaults/models.py
=== modified file 'tests/modeltests/field_defaults/models.py'
13 13 from datetime import datetime 14 14 15 15 class Article(models.Model): 16 headline = models.CharField(max length=100, default='Default headline')16 headline = models.CharField(max_length=100, default='Default headline') 17 17 pub_date = models.DateTimeField(default=datetime.now) 18 18 19 19 def __unicode__(self): -
tests/modeltests/fixtures/models.py
=== modified file 'tests/modeltests/fixtures/models.py'
11 11 from django.db import models 12 12 13 13 class Article(models.Model): 14 headline = models.CharField(max length=100, default='Default headline')14 headline = models.CharField(max_length=100, default='Default headline') 15 15 pub_date = models.DateTimeField() 16 16 17 17 def __unicode__(self): -
tests/modeltests/generic_relations/models.py
=== modified file 'tests/modeltests/generic_relations/models.py'
28 28 return self.tag 29 29 30 30 class Animal(models.Model): 31 common_name = models.CharField(max length=150)32 latin_name = models.CharField(max length=150)31 common_name = models.CharField(max_length=150) 32 latin_name = models.CharField(max_length=150) 33 33 34 34 tags = generic.GenericRelation(TaggedItem) 35 35 … … 37 37 return self.common_name 38 38 39 39 class Vegetable(models.Model): 40 name = models.CharField(max length=150)40 name = models.CharField(max_length=150) 41 41 is_yucky = models.BooleanField(default=True) 42 42 43 43 tags = generic.GenericRelation(TaggedItem) … … 46 46 return self.name 47 47 48 48 class Mineral(models.Model): 49 name = models.CharField(max length=150)49 name = models.CharField(max_length=150) 50 50 hardness = models.PositiveSmallIntegerField() 51 51 52 52 # note the lack of an explicit GenericRelation here... -
tests/modeltests/get_latest/models.py
=== modified file 'tests/modeltests/get_latest/models.py'
11 11 from django.db import models 12 12 13 13 class Article(models.Model): 14 headline = models.CharField(max length=100)14 headline = models.CharField(max_length=100) 15 15 pub_date = models.DateField() 16 16 expire_date = models.DateField() 17 17 class Meta: … … 21 21 return self.headline 22 22 23 23 class Person(models.Model): 24 name = models.CharField(max length=30)24 name = models.CharField(max_length=30) 25 25 birthday = models.DateField() 26 26 27 27 # Note that this model doesn't have "get_latest_by" set. -
tests/modeltests/get_object_or_404/models.py
=== modified file 'tests/modeltests/get_object_or_404/models.py'
15 15 from django.shortcuts import get_object_or_404, get_list_or_404 16 16 17 17 class Author(models.Model): 18 name = models.CharField(max length=50)18 name = models.CharField(max_length=50) 19 19 20 20 def __unicode__(self): 21 21 return self.name … … 26 26 27 27 class Article(models.Model): 28 28 authors = models.ManyToManyField(Author) 29 title = models.CharField(max length=50)29 title = models.CharField(max_length=50) 30 30 objects = models.Manager() 31 31 by_a_sir = ArticleManager() 32 32 -
tests/modeltests/get_or_create/models.py
=== modified file 'tests/modeltests/get_or_create/models.py'
8 8 from django.db import models 9 9 10 10 class Person(models.Model): 11 first_name = models.CharField(max length=100)12 last_name = models.CharField(max length=100)11 first_name = models.CharField(max_length=100) 12 last_name = models.CharField(max_length=100) 13 13 birthday = models.DateField() 14 14 15 15 def __unicode__(self): -
tests/modeltests/invalid_models/models.py
=== modified file 'tests/modeltests/invalid_models/models.py'
10 10 charfield = models.CharField() 11 11 decimalfield = models.DecimalField() 12 12 filefield = models.FileField() 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')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') 17 17 18 18 class Target(models.Model): 19 tgt_safe = models.CharField(max length=10)20 clash1 = models.CharField(max length=10)21 clash2 = models.CharField(max length=10)19 tgt_safe = models.CharField(max_length=10) 20 clash1 = models.CharField(max_length=10) 21 clash2 = models.CharField(max_length=10) 22 22 23 clash1_set = models.CharField(max length=10)23 clash1_set = models.CharField(max_length=10) 24 24 25 25 class Clash1(models.Model): 26 src_safe = models.CharField(max length=10, core=True)26 src_safe = models.CharField(max_length=10, core=True) 27 27 28 28 foreign = models.ForeignKey(Target) 29 29 m2m = models.ManyToManyField(Target) 30 30 31 31 class Clash2(models.Model): 32 src_safe = models.CharField(max length=10, core=True)32 src_safe = models.CharField(max_length=10, core=True) 33 33 34 34 foreign_1 = models.ForeignKey(Target, related_name='id') 35 35 foreign_2 = models.ForeignKey(Target, related_name='src_safe') … … 38 38 m2m_2 = models.ManyToManyField(Target, related_name='src_safe') 39 39 40 40 class Target2(models.Model): 41 clash3 = models.CharField(max length=10)41 clash3 = models.CharField(max_length=10) 42 42 foreign_tgt = models.ForeignKey(Target) 43 43 clashforeign_set = models.ForeignKey(Target) 44 44 … … 46 46 clashm2m_set = models.ManyToManyField(Target) 47 47 48 48 class Clash3(models.Model): 49 src_safe = models.CharField(max length=10, core=True)49 src_safe = models.CharField(max_length=10, core=True) 50 50 51 51 foreign_1 = models.ForeignKey(Target2, related_name='foreign_tgt') 52 52 foreign_2 = models.ForeignKey(Target2, related_name='m2m_tgt') … … 61 61 m2m = models.ManyToManyField(Target2) 62 62 63 63 class SelfClashForeign(models.Model): 64 src_safe = models.CharField(max length=10, core=True)65 selfclashforeign = models.CharField(max length=10)64 src_safe = models.CharField(max_length=10, core=True) 65 selfclashforeign = models.CharField(max_length=10) 66 66 67 67 selfclashforeign_set = models.ForeignKey("SelfClashForeign") 68 68 foreign_1 = models.ForeignKey("SelfClashForeign", related_name='id') 69 69 foreign_2 = models.ForeignKey("SelfClashForeign", related_name='src_safe') 70 70 71 71 class ValidM2M(models.Model): 72 src_safe = models.CharField(max length=10)73 validm2m = models.CharField(max length=10)72 src_safe = models.CharField(max_length=10) 73 validm2m = models.CharField(max_length=10) 74 74 75 75 # M2M fields are symmetrical by default. Symmetrical M2M fields 76 76 # on self don't require a related accessor, so many potential … … 84 84 m2m_4 = models.ManyToManyField('self') 85 85 86 86 class SelfClashM2M(models.Model): 87 src_safe = models.CharField(max length=10)88 selfclashm2m = models.CharField(max length=10)87 src_safe = models.CharField(max_length=10) 88 selfclashm2m = models.CharField(max_length=10) 89 89 90 90 # Non-symmetrical M2M fields _do_ have related accessors, so 91 91 # there is potential for clashes. … … 100 100 class Model(models.Model): 101 101 "But it's valid to call a model Model." 102 102 year = models.PositiveIntegerField() #1960 103 make = models.CharField(max length=10) #Aston Martin104 name = models.CharField(max length=10) #DB 4 GT103 make = models.CharField(max_length=10) #Aston Martin 104 name = models.CharField(max_length=10) #DB 4 GT 105 105 106 106 class Car(models.Model): 107 colour = models.CharField(max length=5)107 colour = models.CharField(max_length=5) 108 108 model = models.ForeignKey(Model) 109 109 110 model_errors = """invalid_models.fielderrors: "charfield": CharFields require a "max length" attribute.110 model_errors = """invalid_models.fielderrors: "charfield": CharFields require a "max_length" attribute. 111 111 invalid_models.fielderrors: "decimalfield": DecimalFields require a "decimal_places" attribute. 112 112 invalid_models.fielderrors: "decimalfield": DecimalFields require a "max_digits" attribute. 113 113 invalid_models.fielderrors: "filefield": FileFields require an "upload_to" attribute. -
tests/modeltests/lookup/models.py
=== modified file 'tests/modeltests/lookup/models.py'
8 8 from django.conf import settings 9 9 10 10 class Article(models.Model): 11 headline = models.CharField(max length=100)11 headline = models.CharField(max_length=100) 12 12 pub_date = models.DateTimeField() 13 13 class Meta: 14 14 ordering = ('-pub_date', 'headline') -
tests/modeltests/m2m_and_m2o/models.py
=== modified file 'tests/modeltests/m2m_and_m2o/models.py'
7 7 from django.db import models 8 8 9 9 class User(models.Model): 10 username = models.CharField(max length=20)10 username = models.CharField(max_length=20) 11 11 12 12 class Issue(models.Model): 13 13 num = models.IntegerField() -
tests/modeltests/m2m_intermediary/models.py
=== modified file 'tests/modeltests/m2m_intermediary/models.py'
13 13 from django.db import models 14 14 15 15 class Reporter(models.Model): 16 first_name = models.CharField(max length=30)17 last_name = models.CharField(max length=30)16 first_name = models.CharField(max_length=30) 17 last_name = models.CharField(max_length=30) 18 18 19 19 def __unicode__(self): 20 20 return u"%s %s" % (self.first_name, self.last_name) 21 21 22 22 class Article(models.Model): 23 headline = models.CharField(max length=100)23 headline = models.CharField(max_length=100) 24 24 pub_date = models.DateField() 25 25 26 26 def __unicode__(self): … … 29 29 class Writer(models.Model): 30 30 reporter = models.ForeignKey(Reporter) 31 31 article = models.ForeignKey(Article) 32 position = models.CharField(max length=100)32 position = models.CharField(max_length=100) 33 33 34 34 def __unicode__(self): 35 35 return u'%s (%s)' % (self.reporter, self.position) -
tests/modeltests/m2m_multiple/models.py
=== modified file 'tests/modeltests/m2m_multiple/models.py'
10 10 from django.db import models 11 11 12 12 class Category(models.Model): 13 name = models.CharField(max length=20)13 name = models.CharField(max_length=20) 14 14 class Meta: 15 15 ordering = ('name',) 16 16 … … 18 18 return self.name 19 19 20 20 class Article(models.Model): 21 headline = models.CharField(max length=50)21 headline = models.CharField(max_length=50) 22 22 pub_date = models.DateTimeField() 23 23 primary_categories = models.ManyToManyField(Category, related_name='primary_article_set') 24 24 secondary_categories = models.ManyToManyField(Category, related_name='secondary_article_set') -
tests/modeltests/m2m_recursive/models.py
=== modified file 'tests/modeltests/m2m_recursive/models.py'
15 15 from django.db import models 16 16 17 17 class Person(models.Model): 18 name = models.CharField(max length=20)18 name = models.CharField(max_length=20) 19 19 friends = models.ManyToManyField('self') 20 20 idols = models.ManyToManyField('self', symmetrical=False, related_name='stalkers') 21 21 -
tests/modeltests/m2o_recursive/models.py
=== modified file 'tests/modeltests/m2o_recursive/models.py'
13 13 from django.db import models 14 14 15 15 class Category(models.Model): 16 name = models.CharField(max length=20)16 name = models.CharField(max_length=20) 17 17 parent = models.ForeignKey('self', null=True, related_name='child_set') 18 18 19 19 def __unicode__(self): -
tests/modeltests/m2o_recursive2/models.py
=== modified file 'tests/modeltests/m2o_recursive2/models.py'
10 10 from django.db import models 11 11 12 12 class Person(models.Model): 13 full_name = models.CharField(max length=20)13 full_name = models.CharField(max_length=20) 14 14 mother = models.ForeignKey('self', null=True, related_name='mothers_child_set') 15 15 father = models.ForeignKey('self', null=True, related_name='fathers_child_set') 16 16 -
tests/modeltests/manipulators/models.py
=== modified file 'tests/modeltests/manipulators/models.py'
7 7 from django.db import models 8 8 9 9 class Musician(models.Model): 10 first_name = models.CharField(max length=30)11 last_name = models.CharField(max length=30)10 first_name = models.CharField(max_length=30) 11 last_name = models.CharField(max_length=30) 12 12 13 13 def __unicode__(self): 14 14 return u"%s %s" % (self.first_name, self.last_name) 15 15 16 16 class Album(models.Model): 17 name = models.CharField(max length=100)17 name = models.CharField(max_length=100) 18 18 musician = models.ForeignKey(Musician) 19 19 release_date = models.DateField(blank=True, null=True) 20 20 -
tests/modeltests/many_to_many/models.py
=== modified file 'tests/modeltests/many_to_many/models.py'
10 10 from django.db import models 11 11 12 12 class Publication(models.Model): 13 title = models.CharField(max length=30)13 title = models.CharField(max_length=30) 14 14 15 15 def __unicode__(self): 16 16 return self.title … … 19 19 ordering = ('title',) 20 20 21 21 class Article(models.Model): 22 headline = models.CharField(max length=100)22 headline = models.CharField(max_length=100) 23 23 publications = models.ManyToManyField(Publication) 24 24 25 25 def __unicode__(self): -
tests/modeltests/many_to_one/models.py
=== modified file 'tests/modeltests/many_to_one/models.py'
7 7 from django.db import models 8 8 9 9 class Reporter(models.Model): 10 first_name = models.CharField(max length=30)11 last_name = models.CharField(max length=30)10 first_name = models.CharField(max_length=30) 11 last_name = models.CharField(max_length=30) 12 12 email = models.EmailField() 13 13 14 14 def __unicode__(self): 15 15 return u"%s %s" % (self.first_name, self.last_name) 16 16 17 17 class Article(models.Model): 18 headline = models.CharField(max length=100)18 headline = models.CharField(max_length=100) 19 19 pub_date = models.DateField() 20 20 reporter = models.ForeignKey(Reporter) 21 21 -
tests/modeltests/many_to_one_null/models.py
=== modified file 'tests/modeltests/many_to_one_null/models.py'
8 8 from django.db import models 9 9 10 10 class Reporter(models.Model): 11 name = models.CharField(max length=30)11 name = models.CharField(max_length=30) 12 12 13 13 def __unicode__(self): 14 14 return self.name 15 15 16 16 class Article(models.Model): 17 headline = models.CharField(max length=100)17 headline = models.CharField(max_length=100) 18 18 reporter = models.ForeignKey(Reporter, null=True) 19 19 20 20 class Meta: -
tests/modeltests/model_forms/models.py
=== modified file 'tests/modeltests/model_forms/models.py'
31 31 ) 32 32 33 33 class Category(models.Model): 34 name = models.CharField(max length=20)35 url = models.CharField('The URL', max length=40)34 name = models.CharField(max_length=20) 35 url = models.CharField('The URL', max_length=40) 36 36 37 37 def __unicode__(self): 38 38 return self.name 39 39 40 40 class Writer(models.Model): 41 name = models.CharField(max length=50, help_text='Use both first and last names.')41 name = models.CharField(max_length=50, help_text='Use both first and last names.') 42 42 43 43 def __unicode__(self): 44 44 return self.name 45 45 46 46 class Article(models.Model): 47 headline = models.CharField(max length=50)47 headline = models.CharField(max_length=50) 48 48 pub_date = models.DateField() 49 49 created = models.DateField(editable=False) 50 50 writer = models.ForeignKey(Writer) … … 63 63 64 64 class PhoneNumber(models.Model): 65 65 phone = models.PhoneNumberField() 66 description = models.CharField(max length=20)66 description = models.CharField(max_length=20) 67 67 68 68 def __unicode__(self): 69 69 return self.phone -
tests/modeltests/model_inheritance/models.py
=== modified file 'tests/modeltests/model_inheritance/models.py'
7 7 from django.db import models 8 8 9 9 class Place(models.Model): 10 name = models.CharField(max length=50)11 address = models.CharField(max length=80)10 name = models.CharField(max_length=50) 11 address = models.CharField(max_length=80) 12 12 13 13 def __unicode__(self): 14 14 return u"%s the place" % self.name -
tests/modeltests/mutually_referential/models.py
=== modified file 'tests/modeltests/mutually_referential/models.py'
7 7 from django.db.models import * 8 8 9 9 class Parent(Model): 10 name = CharField(max length=100, core=True)10 name = CharField(max_length=100, core=True) 11 11 bestchild = ForeignKey("Child", null=True, related_name="favoured_by") 12 12 13 13 class Child(Model): 14 name = CharField(max length=100)14 name = CharField(max_length=100) 15 15 parent = ForeignKey(Parent) 16 16 17 17 __test__ = {'API_TESTS':""" -
tests/modeltests/one_to_one/models.py
=== modified file 'tests/modeltests/one_to_one/models.py'
9 9 from django.db import models 10 10 11 11 class Place(models.Model): 12 name = models.CharField(max length=50)13 address = models.CharField(max length=80)12 name = models.CharField(max_length=50) 13 address = models.CharField(max_length=80) 14 14 15 15 def __unicode__(self): 16 16 return u"%s the place" % self.name … … 25 25 26 26 class Waiter(models.Model): 27 27 restaurant = models.ForeignKey(Restaurant) 28 name = models.CharField(max length=50)28 name = models.CharField(max_length=50) 29 29 30 30 def __unicode__(self): 31 31 return u"%s the waiter at %s" % (self.name, self.restaurant) 32 32 33 33 class ManualPrimaryKey(models.Model): 34 primary_key = models.CharField(max length=10, primary_key=True)35 name = models.CharField(max length = 50)34 primary_key = models.CharField(max_length=10, primary_key=True) 35 name = models.CharField(max_length = 50) 36 36 37 37 class RelatedModel(models.Model): 38 38 link = models.OneToOneField(ManualPrimaryKey) 39 name = models.CharField(max length = 50)39 name = models.CharField(max_length = 50) 40 40 41 41 __test__ = {'API_TESTS':""" 42 42 # Create a couple of Places. -
tests/modeltests/or_lookups/models.py
=== modified file 'tests/modeltests/or_lookups/models.py'
14 14 from django.db import models 15 15 16 16 class Article(models.Model): 17 headline = models.CharField(max length=50)17 headline = models.CharField(max_length=50) 18 18 pub_date = models.DateTimeField() 19 19 20 20 class Meta: -
tests/modeltests/ordering/models.py
=== modified file 'tests/modeltests/ordering/models.py'
16 16 from django.db import models 17 17 18 18 class Article(models.Model): 19 headline = models.CharField(max length=100)19 headline = models.CharField(max_length=100) 20 20 pub_date = models.DateTimeField() 21 21 class Meta: 22 22 ordering = ('-pub_date', 'headline') -
tests/modeltests/pagination/models.py
=== modified file 'tests/modeltests/pagination/models.py'
9 9 from django.db import models 10 10 11 11 class Article(models.Model): 12 headline = models.CharField(max length=100, default='Default headline')12 headline = models.CharField(max_length=100, default='Default headline') 13 13 pub_date = models.DateTimeField() 14 14 15 15 def __unicode__(self): -
tests/modeltests/properties/models.py
=== modified file 'tests/modeltests/properties/models.py'
7 7 from django.db import models 8 8 9 9 class Person(models.Model): 10 first_name = models.CharField(max length=30)11 last_name = models.CharField(max length=30)10 first_name = models.CharField(max_length=30) 11 last_name = models.CharField(max_length=30) 12 12 13 13 def _get_full_name(self): 14 14 return "%s %s" % (self.first_name, self.last_name) -
tests/modeltests/reserved_names/models.py
=== modified file 'tests/modeltests/reserved_names/models.py'
10 10 from django.db import models 11 11 12 12 class Thing(models.Model): 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')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') 21 21 class Meta: 22 22 db_table = 'select' 23 23 -
tests/modeltests/reverse_lookup/models.py
=== modified file 'tests/modeltests/reverse_lookup/models.py'
7 7 from django.db import models 8 8 9 9 class User(models.Model): 10 name = models.CharField(max length=200)10 name = models.CharField(max_length=200) 11 11 12 12 def __unicode__(self): 13 13 return self.name 14 14 15 15 class Poll(models.Model): 16 question = models.CharField(max length=200)16 question = models.CharField(max_length=200) 17 17 creator = models.ForeignKey(User) 18 18 19 19 def __unicode__(self): 20 20 return self.question 21 21 22 22 class Choice(models.Model): 23 name = models.CharField(max length=100)23 name = models.CharField(max_length=100) 24 24 poll = models.ForeignKey(Poll, related_name="poll_choice") 25 25 related_poll = models.ForeignKey(Poll, related_name="related_choice") 26 26 -
tests/modeltests/save_delete_hooks/models.py
=== modified file 'tests/modeltests/save_delete_hooks/models.py'
8 8 from django.db import models 9 9 10 10 class Person(models.Model): 11 first_name = models.CharField(max length=20)12 last_name = models.CharField(max length=20)11 first_name = models.CharField(max_length=20) 12 last_name = models.CharField(max_length=20) 13 13 14 14 def __unicode__(self): 15 15 return u"%s %s" % (self.first_name, self.last_name) -
tests/modeltests/select_related/models.py
=== modified file 'tests/modeltests/select_related/models.py'
12 12 # Who remembers high school biology? 13 13 14 14 class Domain(models.Model): 15 name = models.CharField(max length=50)15 name = models.CharField(max_length=50) 16 16 def __unicode__(self): 17 17 return self.name 18 18 19 19 class Kingdom(models.Model): 20 name = models.CharField(max length=50)20 name = models.CharField(max_length=50) 21 21 domain = models.ForeignKey(Domain) 22 22 def __unicode__(self): 23 23 return self.name 24 24 25 25 class Phylum(models.Model): 26 name = models.CharField(max length=50)26 name = models.CharField(max_length=50) 27 27 kingdom = models.ForeignKey(Kingdom) 28 28 def __unicode__(self): 29 29 return self.name 30 30 31 31 class Klass(models.Model): 32 name = models.CharField(max length=50)32 name = models.CharField(max_length=50) 33 33 phylum = models.ForeignKey(Phylum) 34 34 def __unicode__(self): 35 35 return self.name 36 36 37 37 class Order(models.Model): 38 name = models.CharField(max length=50)38 name = models.CharField(max_length=50) 39 39 klass = models.ForeignKey(Klass) 40 40 def __unicode__(self): 41 41 return self.name 42 42 43 43 class Family(models.Model): 44 name = models.CharField(max length=50)44 name = models.CharField(max_length=50) 45 45 order = models.ForeignKey(Order) 46 46 def __unicode__(self): 47 47 return self.name 48 48 49 49 class Genus(models.Model): 50 name = models.CharField(max length=50)50 name = models.CharField(max_length=50) 51 51 family = models.ForeignKey(Family) 52 52 def __unicode__(self): 53 53 return self.name 54 54 55 55 class Species(models.Model): 56 name = models.CharField(max length=50)56 name = models.CharField(max_length=50) 57 57 genus = models.ForeignKey(Genus) 58 58 def __unicode__(self): 59 59 return self.name -
tests/modeltests/serializers/models.py
=== modified file 'tests/modeltests/serializers/models.py'
8 8 from django.db import models 9 9 10 10 class Category(models.Model): 11 name = models.CharField(max length=20)11 name = models.CharField(max_length=20) 12 12 13 13 class Meta: 14 14 ordering = ('name',) … … 17 17 return self.name 18 18 19 19 class Author(models.Model): 20 name = models.CharField(max length=20)20 name = models.CharField(max_length=20) 21 21 22 22 class Meta: 23 23 ordering = ('name',) … … 27 27 28 28 class Article(models.Model): 29 29 author = models.ForeignKey(Author) 30 headline = models.CharField(max length=50)30 headline = models.CharField(max_length=50) 31 31 pub_date = models.DateTimeField() 32 32 categories = models.ManyToManyField(Category) 33 33 -
tests/modeltests/str/models.py
=== modified file 'tests/modeltests/str/models.py'
17 17 from django.db import models 18 18 19 19 class Article(models.Model): 20 headline = models.CharField(max length=100)20 headline = models.CharField(max_length=100) 21 21 pub_date = models.DateTimeField() 22 22 23 23 def __str__(self): … … 26 26 return self.headline 27 27 28 28 class InternationalArticle(models.Model): 29 headline = models.CharField(max length=100)29 headline = models.CharField(max_length=100) 30 30 pub_date = models.DateTimeField() 31 31 32 32 def __unicode__(self): -
tests/modeltests/transactions/models.py
=== modified file 'tests/modeltests/transactions/models.py'
10 10 from django.db import models 11 11 12 12 class Reporter(models.Model): 13 first_name = models.CharField(max length=30)14 last_name = models.CharField(max length=30)13 first_name = models.CharField(max_length=30) 14 last_name = models.CharField(max_length=30) 15 15 email = models.EmailField() 16 16 17 17 def __unicode__(self): -
tests/modeltests/validation/models.py
=== modified file 'tests/modeltests/validation/models.py'
12 12 13 13 class Person(models.Model): 14 14 is_child = models.BooleanField() 15 name = models.CharField(max length=20)15 name = models.CharField(max_length=20) 16 16 birthdate = models.DateField() 17 17 favorite_moment = models.DateTimeField() 18 18 email = models.EmailField() -
tests/regressiontests/bug639/models.py
=== modified file 'tests/regressiontests/bug639/models.py'
2 2 from django.db import models 3 3 4 4 class Photo(models.Model): 5 title = models.CharField(max length=30)5 title = models.CharField(max_length=30) 6 6 image = models.FileField(upload_to=tempfile.gettempdir()) 7 7 8 8 # Support code for the tests; this keeps track of how many times save() gets -
tests/regressiontests/datatypes/models.py
=== modified file 'tests/regressiontests/datatypes/models.py'
7 7 from django.conf import settings 8 8 9 9 class Donut(models.Model): 10 name = models.CharField(max length=100)10 name = models.CharField(max_length=100) 11 11 is_frosted = models.BooleanField(default=False) 12 12 has_sprinkles = models.NullBooleanField() 13 13 baked_date = models.DateField(null=True) -
tests/regressiontests/fixtures_regress/models.py
=== modified file 'tests/regressiontests/fixtures_regress/models.py'
2 2 from django.contrib.auth.models import User 3 3 4 4 class Animal(models.Model): 5 name = models.CharField(max length=150)6 latin_name = models.CharField(max length=150)5 name = models.CharField(max_length=150) 6 latin_name = models.CharField(max_length=150) 7 7 8 8 def __unicode__(self): 9 9 return self.common_name 10 10 11 11 class Plant(models.Model): 12 name = models.CharField(max length=150)12 name = models.CharField(max_length=150) 13 13 14 14 class Meta: 15 15 # For testing when upper case letter in app name; regression for #4057 16 16 db_table = "Fixtures_regress_plant" 17 17 18 18 class Stuff(models.Model): 19 name = models.CharField(max length=20, null=True)19 name = models.CharField(max_length=20, null=True) 20 20 owner = models.ForeignKey(User, null=True) 21 21 22 22 def __unicode__(self): -
tests/regressiontests/initial_sql_regress/models.py
=== modified file 'tests/regressiontests/initial_sql_regress/models.py'
5 5 from django.db import models 6 6 7 7 class Simple(models.Model): 8 name = models.CharField(max length = 50)8 name = models.CharField(max_length = 50) 9 9 10 10 __test__ = {'API_TESTS':""} 11 11 -
tests/regressiontests/invalid_admin_options/models.py
=== modified file 'tests/regressiontests/invalid_admin_options/models.py'
12 12 ##This should fail gracefully but is causing a metaclass error 13 13 #class BadAdminOption(models.Model): 14 14 # "Test nonexistent admin option" 15 # name = models.CharField(max length=30)15 # name = models.CharField(max_length=30) 16 16 # 17 17 # class Admin: 18 18 # nonexistent = 'option' … … 22 22 23 23 class ListDisplayBadOne(models.Model): 24 24 "Test list_display, list_display must be a list or tuple" 25 first_name = models.CharField(max length=30)25 first_name = models.CharField(max_length=30) 26 26 27 27 class Admin: 28 28 list_display = 'first_name' … … 32 32 33 33 class ListDisplayBadTwo(models.Model): 34 34 "Test list_display, list_display items must be attributes, methods or properties." 35 first_name = models.CharField(max length=30)35 first_name = models.CharField(max_length=30) 36 36 37 37 class Admin: 38 38 list_display = ['first_name','nonexistent'] … … 41 41 """ 42 42 class ListDisplayBadThree(models.Model): 43 43 "Test list_display, list_display items can not be a ManyToManyField." 44 first_name = models.CharField(max length=30)44 first_name = models.CharField(max_length=30) 45 45 nick_names = models.ManyToManyField('ListDisplayGood') 46 46 47 47 class Admin: … … 52 52 53 53 class ListDisplayGood(models.Model): 54 54 "Test list_display, Admin list_display can be a attribute, method or property." 55 first_name = models.CharField(max length=30)55 first_name = models.CharField(max_length=30) 56 56 57 57 def _last_name(self): 58 58 return self.first_name … … 66 66 67 67 class ListDisplayLinksBadOne(models.Model): 68 68 "Test list_display_links, item must be included in list_display." 69 first_name = models.CharField(max length=30)70 last_name = models.CharField(max length=30)69 first_name = models.CharField(max_length=30) 70 last_name = models.CharField(max_length=30) 71 71 72 72 class Admin: 73 73 list_display = ['last_name'] … … 78 78 79 79 class ListDisplayLinksBadTwo(models.Model): 80 80 "Test list_display_links, must be a list or tuple." 81 first_name = models.CharField(max length=30)82 last_name = models.CharField(max length=30)81 first_name = models.CharField(max_length=30) 82 last_name = models.CharField(max_length=30) 83 83 84 84 class Admin: 85 85 list_display = ['first_name','last_name'] … … 92 92 ## This is failing but the validation which should fail is not. 93 93 #class ListDisplayLinksBadThree(models.Model): 94 94 # "Test list_display_links, must define list_display to use list_display_links." 95 # first_name = models.CharField(max length=30)96 # last_name = models.CharField(max length=30)95 # first_name = models.CharField(max_length=30) 96 # last_name = models.CharField(max_length=30) 97 97 # 98 98 # class Admin: 99 99 # list_display_links = ('first_name',) … … 103 103 104 104 class ListDisplayLinksGood(models.Model): 105 105 "Test list_display_links, Admin list_display_list can be a attribute, method or property." 106 first_name = models.CharField(max length=30)106 first_name = models.CharField(max_length=30) 107 107 108 108 def _last_name(self): 109 109 return self.first_name … … 118 118 119 119 class ListFilterBadOne(models.Model): 120 120 "Test list_filter, must be a list or tuple." 121 first_name = models.CharField(max length=30)121 first_name = models.CharField(max_length=30) 122 122 123 123 class Admin: 124 124 list_filter = 'first_name' … … 128 128 129 129 class ListFilterBadTwo(models.Model): 130 130 "Test list_filter, must be a field not a property or method." 131 first_name = models.CharField(max length=30)131 first_name = models.CharField(max_length=30) 132 132 133 133 def _last_name(self): 134 134 return self.first_name … … 146 146 147 147 class DateHierarchyBadOne(models.Model): 148 148 "Test date_hierarchy, must be a date or datetime field." 149 first_name = models.CharField(max length=30)149 first_name = models.CharField(max_length=30) 150 150 birth_day = models.DateField() 151 151 152 152 class Admin: … … 158 158 159 159 class DateHierarchyBadTwo(models.Model): 160 160 "Test date_hieracrhy, must be a field." 161 first_name = models.CharField(max length=30)161 first_name = models.CharField(max_length=30) 162 162 birth_day = models.DateField() 163 163 164 164 class Admin: … … 169 169 170 170 class DateHierarchyGood(models.Model): 171 171 "Test date_hieracrhy, must be a field." 172 first_name = models.CharField(max length=30)172 first_name = models.CharField(max_length=30) 173 173 birth_day = models.DateField() 174 174 175 175 class Admin: … … 177 177 178 178 class SearchFieldsBadOne(models.Model): 179 179 "Test search_fields, must be a list or tuple." 180 first_name = models.CharField(max length=30)180 first_name = models.CharField(max_length=30) 181 181 182 182 class Admin: 183 183 search_fields = ('nonexistent') … … 188 188 189 189 class SearchFieldsBadTwo(models.Model): 190 190 "Test search_fields, must be a field." 191 first_name = models.CharField(max length=30)191 first_name = models.CharField(max_length=30) 192 192 193 193 def _last_name(self): 194 194 return self.first_name … … 203 203 204 204 class SearchFieldsGood(models.Model): 205 205 "Test search_fields, must be a list or tuple." 206 first_name = models.CharField(max length=30)207 last_name = models.CharField(max length=30)206 first_name = models.CharField(max_length=30) 207 last_name = models.CharField(max_length=30) 208 208 209 209 class Admin: 210 210 search_fields = ['first_name','last_name'] … … 212 212 213 213 class JsBadOne(models.Model): 214 214 "Test js, must be a list or tuple" 215 name = models.CharField(max length=30)215 name = models.CharField(max_length=30) 216 216 217 217 class Admin: 218 218 js = 'test.js' … … 223 223 224 224 class SaveAsBad(models.Model): 225 225 "Test save_as, should be True or False" 226 name = models.CharField(max length=30)226 name = models.CharField(max_length=30) 227 227 228 228 class Admin: 229 229 save_as = 'not True or False' … … 234 234 235 235 class SaveOnTopBad(models.Model): 236 236 "Test save_on_top, should be True or False" 237 name = models.CharField(max length=30)237 name = models.CharField(max_length=30) 238 238 239 239 class Admin: 240 240 save_on_top = 'not True or False' … … 245 245 246 246 class ListSelectRelatedBad(models.Model): 247 247 "Test list_select_related, should be True or False" 248 name = models.CharField(max length=30)248 name = models.CharField(max_length=30) 249 249 250 250 class Admin: 251 251 list_select_related = 'not True or False' … … 256 256 257 257 class ListPerPageBad(models.Model): 258 258 "Test list_per_page, should be a positive integer value." 259 name = models.CharField(max length=30)259 name = models.CharField(max_length=30) 260 260 261 261 class Admin: 262 262 list_per_page = 89.3 … … 267 267 268 268 class FieldsBadOne(models.Model): 269 269 "Test fields, should be a tuple" 270 first_name = models.CharField(max length=30)271 last_name = models.CharField(max length=30)270 first_name = models.CharField(max_length=30) 271 last_name = models.CharField(max_length=30) 272 272 273 273 class Admin: 274 274 fields = 'not a tuple' … … 279 279 280 280 class FieldsBadTwo(models.Model): 281 281 """Test fields, 'fields' dict option is required.""" 282 first_name = models.CharField(max length=30)283 last_name = models.CharField(max length=30)282 first_name = models.CharField(max_length=30) 283 last_name = models.CharField(max_length=30) 284 284 285 285 class Admin: 286 286 fields = ('Name', {'description': 'this fieldset needs fields'}) … … 291 291 292 292 class FieldsBadThree(models.Model): 293 293 """Test fields, 'classes' and 'description' are the only allowable extra dict options.""" 294 first_name = models.CharField(max length=30)295 last_name = models.CharField(max length=30)294 first_name = models.CharField(max_length=30) 295 last_name = models.CharField(max_length=30) 296 296 297 297 class Admin: 298 298 fields = ('Name', {'fields': ('first_name','last_name'),'badoption': 'verybadoption'}) … … 303 303 304 304 class FieldsGood(models.Model): 305 305 "Test fields, working example" 306 first_name = models.CharField(max length=30)307 last_name = models.CharField(max length=30)306 first_name = models.CharField(max_length=30) 307 last_name = models.CharField(max_length=30) 308 308 birth_day = models.DateField() 309 309 310 310 class Admin: … … 315 315 316 316 class OrderingBad(models.Model): 317 317 "Test ordering, must be a field." 318 first_name = models.CharField(max length=30)319 last_name = models.CharField(max length=30)318 first_name = models.CharField(max_length=30) 319 last_name = models.CharField(max_length=30) 320 320 321 321 class Admin: 322 322 ordering = 'nonexistent' … … 328 328 ## TODO: Add a manager validator, this should fail gracefully. 329 329 #class ManagerBad(models.Model): 330 330 # "Test manager, must be a manager object." 331 # first_name = models.CharField(max length=30)331 # first_name = models.CharField(max_length=30) 332 332 # 333 333 # class Admin: 334 334 # manager = 'nonexistent' -
tests/regressiontests/many_to_one_regress/models.py
=== modified file 'tests/regressiontests/many_to_one_regress/models.py'
12 12 13 13 # Protect against repetition of #1839, #2415 and #2536. 14 14 class Third(models.Model): 15 name = models.CharField(max length=20)15 name = models.CharField(max_length=20) 16 16 third = models.ForeignKey('self', null=True, related_name='child_set') 17 17 18 18 class Parent(models.Model): 19 name = models.CharField(max length=20)19 name = models.CharField(max_length=20) 20 20 bestchild = models.ForeignKey('Child', null=True, related_name='favored_by') 21 21 22 22 class Child(models.Model): 23 name = models.CharField(max length=20)23 name = models.CharField(max_length=20) 24 24 parent = models.ForeignKey(Parent) 25 25 26 26 -
tests/regressiontests/model_regress/models.py
=== modified file 'tests/regressiontests/model_regress/models.py'
7 7 ) 8 8 9 9 class Article(models.Model): 10 headline = models.CharField(max length=100, default='Default headline')10 headline = models.CharField(max_length=100, default='Default headline') 11 11 pub_date = models.DateTimeField() 12 12 status = models.IntegerField(blank=True, null=True, choices=CHOICES) 13 13 -
tests/regressiontests/null_queries/models.py
=== modified file 'tests/regressiontests/null_queries/models.py'
1 1 from django.db import models 2 2 3 3 class Poll(models.Model): 4 question = models.CharField(max length=200)4 question = models.CharField(max_length=200) 5 5 6 6 def __unicode__(self): 7 7 return u"Q: %s " % self.question 8 8 9 9 class Choice(models.Model): 10 10 poll = models.ForeignKey(Poll) 11 choice = models.CharField(max length=200)11 choice = models.CharField(max_length=200) 12 12 13 13 def __unicode__(self): 14 14 return u"Choice: %s in poll %s" % (self.choice, self.poll) -
tests/regressiontests/one_to_one_regress/models.py
=== modified file 'tests/regressiontests/one_to_one_regress/models.py'
1 1 from django.db import models 2 2 3 3 class Place(models.Model): 4 name = models.CharField(max length=50)5 address = models.CharField(max length=80)4 name = models.CharField(max_length=50) 5 address = models.CharField(max_length=80) 6 6 7 7 def __unicode__(self): 8 8 return u"%s the place" % self.name … … 16 16 return u"%s the restaurant" % self.place.name 17 17 18 18 class Favorites(models.Model): 19 name = models.CharField(max length = 50)19 name = models.CharField(max_length = 50) 20 20 restaurants = models.ManyToManyField(Restaurant) 21 21 22 22 def __unicode__(self): -
tests/regressiontests/serializers_regress/models.py
=== modified file 'tests/regressiontests/serializers_regress/models.py'
16 16 data = models.BooleanField(null=True) 17 17 18 18 class CharData(models.Model): 19 data = models.CharField(max length=30, null=True)19 data = models.CharField(max_length=30, null=True) 20 20 21 21 class DateData(models.Model): 22 22 data = models.DateField(null=True) … … 90 90 ordering = ["data"] 91 91 92 92 class GenericData(models.Model): 93 data = models.CharField(max length=30)93 data = models.CharField(max_length=30) 94 94 95 95 tags = generic.GenericRelation(Tag) 96 96 … … 102 102 """This is a model that can be used as 103 103 something for other models to point at""" 104 104 105 data = models.CharField(max length=30)105 data = models.CharField(max_length=30) 106 106 107 107 class UniqueAnchor(models.Model): 108 108 """This is a model that can be used as 109 109 something for other models to point at""" 110 110 111 data = models.CharField(unique=True, max length=30)111 data = models.CharField(unique=True, max_length=30) 112 112 113 113 class FKData(models.Model): 114 114 data = models.ForeignKey(Anchor, null=True) … … 144 144 data = models.BooleanField(primary_key=True) 145 145 146 146 class CharPKData(models.Model): 147 data = models.CharField(max length=30, primary_key=True)147 data = models.CharField(max_length=30, primary_key=True) 148 148 149 149 # class DatePKData(models.Model): 150 150 # data = models.DateField(primary_key=True) … … 208 208 # data = models.XMLField(primary_key=True) 209 209 210 210 class ComplexModel(models.Model): 211 field1 = models.CharField(max length=10)212 field2 = models.CharField(max length=10)213 field3 = models.CharField(max length=10)211 field1 = models.CharField(max_length=10) 212 field2 = models.CharField(max_length=10) 213 field3 = models.CharField(max_length=10) 214 214 215 215 # Tests for handling fields with pre_save functions, or 216 216 # models with save functions that modify data -
tests/regressiontests/string_lookup/models.py
=== modified file 'tests/regressiontests/string_lookup/models.py'
2 2 from django.db import models 3 3 4 4 class Foo(models.Model): 5 name = models.CharField(max length=50)6 friend = models.CharField(max length=50, blank=True)5 name = models.CharField(max_length=50) 6 friend = models.CharField(max_length=50, blank=True) 7 7 8 8 def __unicode__(self): 9 9 return "Foo %s" % self.name 10 10 11 11 class Bar(models.Model): 12 name = models.CharField(max length=50)12 name = models.CharField(max_length=50) 13 13 normal = models.ForeignKey(Foo, related_name='normal_foo') 14 14 fwd = models.ForeignKey("Whiz") 15 15 back = models.ForeignKey("Foo") … … 18 18 return "Bar %s" % self.place.name 19 19 20 20 class Whiz(models.Model): 21 name = models.CharField(max length = 50)21 name = models.CharField(max_length = 50) 22 22 23 23 def __unicode__(self): 24 24 return "Whiz %s" % self.name 25 25 26 26 class Child(models.Model): 27 27 parent = models.OneToOneField('Base') 28 name = models.CharField(max length = 50)28 name = models.CharField(max_length = 50) 29 29 30 30 def __unicode__(self): 31 31 return "Child %s" % self.name 32 32 33 33 class Base(models.Model): 34 name = models.CharField(max length = 50)34 name = models.CharField(max_length = 50) 35 35 36 36 def __unicode__(self): 37 37 return "Base %s" % self.name