Ticket #2101: max_length.2.patch
File max_length.2.patch, 117.3 KB (added by , 18 years ago) |
---|
-
django/contrib/admin/models.py
17 17 user = models.ForeignKey(User) 18 18 content_type = models.ForeignKey(ContentType, blank=True, null=True) 19 19 object_id = models.TextField(_('object id'), blank=True, null=True) 20 object_repr = models.CharField(_('object repr'), max length=200)20 object_repr = models.CharField(_('object repr'), max_length=200) 21 21 action_flag = models.PositiveSmallIntegerField(_('action flag')) 22 22 change_message = models.TextField(_('change message'), blank=True) 23 23 objects = LogEntryManager() -
django/contrib/admin/templatetags/admin_modify.py
189 189 t.append('document.getElementById("id_%s").onkeyup = function() {' \ 190 190 ' var e = document.getElementById("id_%s");' \ 191 191 ' if(!e._changed) { e.value = URLify(%s, %s);} }; ' % ( 192 f, field.name, add_values, field.max length))192 f, field.name, add_values, field.max_length)) 193 193 return ''.join(t) 194 194 auto_populated_field_script = register.simple_tag(auto_populated_field_script) 195 195 -
django/contrib/admin/views/doc.py
290 290 DATA_TYPE_MAPPING = { 291 291 'AutoField' : _('Integer'), 292 292 'BooleanField' : _('Boolean (Either True or False)'), 293 'CharField' : _('String (up to %(max length)s)'),293 'CharField' : _('String (up to %(max_length)s)'), 294 294 'CommaSeparatedIntegerField': _('Comma-separated integers'), 295 295 'DateField' : _('Date (without time)'), 296 296 'DateTimeField' : _('Date (with time)'), … … 308 308 'PhoneNumberField' : _('Phone number'), 309 309 'PositiveIntegerField' : _('Integer'), 310 310 'PositiveSmallIntegerField' : _('Integer'), 311 'SlugField' : _('String (up to %(max length)s)'),311 'SlugField' : _('String (up to %(max_length)s)'), 312 312 'SmallIntegerField' : _('Integer'), 313 313 'TextField' : _('Text'), 314 314 'TimeField' : _('Time'), -
django/contrib/auth/forms.py
9 9 "A form that creates a user, with no privileges, from the given username and password." 10 10 def __init__(self): 11 11 self.fields = ( 12 oldforms.TextField(field_name='username', length=30, max length=30, is_required=True,12 oldforms.TextField(field_name='username', length=30, max_length=30, is_required=True, 13 13 validator_list=[validators.isAlphaNumeric, self.isValidUsername]), 14 oldforms.PasswordField(field_name='password1', length=30, max length=60, is_required=True),15 oldforms.PasswordField(field_name='password2', length=30, max length=60, is_required=True,14 oldforms.PasswordField(field_name='password1', length=30, max_length=60, is_required=True), 15 oldforms.PasswordField(field_name='password2', length=30, max_length=60, is_required=True, 16 16 validator_list=[validators.AlwaysMatchesOtherField('password1', _("The two password fields didn't match."))]), 17 17 ) 18 18 … … 41 41 """ 42 42 self.request = request 43 43 self.fields = [ 44 oldforms.TextField(field_name="username", length=15, max length=30, is_required=True,44 oldforms.TextField(field_name="username", length=15, max_length=30, is_required=True, 45 45 validator_list=[self.isValidUser, self.hasCookiesEnabled]), 46 oldforms.PasswordField(field_name="password", length=15, max length=30, is_required=True),46 oldforms.PasswordField(field_name="password", length=15, max_length=30, is_required=True), 47 47 ] 48 48 self.user_cache = None 49 49 … … 110 110 def __init__(self, user): 111 111 self.user = user 112 112 self.fields = ( 113 oldforms.PasswordField(field_name="old_password", length=30, max length=30, is_required=True,113 oldforms.PasswordField(field_name="old_password", length=30, max_length=30, is_required=True, 114 114 validator_list=[self.isValidOldPassword]), 115 oldforms.PasswordField(field_name="new_password1", length=30, max length=30, is_required=True,115 oldforms.PasswordField(field_name="new_password1", length=30, max_length=30, is_required=True, 116 116 validator_list=[validators.AlwaysMatchesOtherField('new_password2', _("The two 'new password' fields didn't match."))]), 117 oldforms.PasswordField(field_name="new_password2", length=30, max length=30, is_required=True),117 oldforms.PasswordField(field_name="new_password2", length=30, max_length=30, is_required=True), 118 118 ) 119 119 120 120 def isValidOldPassword(self, new_data, all_data): … … 132 132 def __init__(self, user): 133 133 self.user = user 134 134 self.fields = ( 135 oldforms.PasswordField(field_name='password1', length=30, max length=60, is_required=True),136 oldforms.PasswordField(field_name='password2', length=30, max length=60, is_required=True,135 oldforms.PasswordField(field_name='password1', length=30, max_length=60, is_required=True), 136 oldforms.PasswordField(field_name='password2', length=30, max_length=60, is_required=True, 137 137 validator_list=[validators.AlwaysMatchesOtherField('password1', _("The two password fields didn't match."))]), 138 138 ) 139 139 -
django/contrib/auth/models.py
35 35 36 36 Three basic permissions -- add, change and delete -- are automatically created for each Django model. 37 37 """ 38 name = models.CharField(_('name'), max length=50)38 name = models.CharField(_('name'), max_length=50) 39 39 content_type = models.ForeignKey(ContentType) 40 codename = models.CharField(_('codename'), max length=100)40 codename = models.CharField(_('codename'), max_length=100) 41 41 class Meta: 42 42 verbose_name = _('permission') 43 43 verbose_name_plural = _('permissions') … … 54 54 55 55 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. 56 56 """ 57 name = models.CharField(_('name'), max length=80, unique=True)57 name = models.CharField(_('name'), max_length=80, unique=True) 58 58 permissions = models.ManyToManyField(Permission, verbose_name=_('permissions'), blank=True, filter_interface=models.HORIZONTAL) 59 59 class Meta: 60 60 verbose_name = _('group') … … 87 87 88 88 Username and password are required. Other fields are optional. 89 89 """ 90 username = models.CharField(_('username'), max length=30, unique=True, validator_list=[validators.isAlphaNumeric], help_text=_("Required. 30 characters or fewer. Alphanumeric characters only (letters, digits and underscores)."))91 first_name = models.CharField(_('first name'), max length=30, blank=True)92 last_name = models.CharField(_('last name'), max length=30, blank=True)90 username = models.CharField(_('username'), max_length=30, unique=True, validator_list=[validators.isAlphaNumeric], help_text=_("Required. 30 characters or fewer. Alphanumeric characters only (letters, digits and underscores).")) 91 first_name = models.CharField(_('first name'), max_length=30, blank=True) 92 last_name = models.CharField(_('last name'), max_length=30, blank=True) 93 93 email = models.EmailField(_('e-mail address'), blank=True) 94 password = models.CharField(_('password'), max length=128, help_text=_("Use '[algo]$[salt]$[hexdigest]' or use the <a href=\"password/\">change password form</a>."))94 password = models.CharField(_('password'), max_length=128, help_text=_("Use '[algo]$[salt]$[hexdigest]' or use the <a href=\"password/\">change password form</a>.")) 95 95 is_staff = models.BooleanField(_('staff status'), default=False, help_text=_("Designates whether the user can log into this admin site.")) 96 96 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.")) 97 97 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
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
28 28 else: 29 29 return [] 30 30 self.fields.extend([ 31 oldforms.LargeTextField(field_name="comment", max length=3000, is_required=True,31 oldforms.LargeTextField(field_name="comment", max_length=3000, is_required=True, 32 32 validator_list=[self.hasNoProfanities]), 33 33 oldforms.RadioSelectField(field_name="rating1", choices=choices, 34 34 is_required=ratings_required and num_rating_choices > 0, … … 121 121 "Manipulator that handles public free (unregistered) comments" 122 122 def __init__(self): 123 123 self.fields = ( 124 oldforms.TextField(field_name="person_name", max length=50, is_required=True,124 oldforms.TextField(field_name="person_name", max_length=50, is_required=True, 125 125 validator_list=[self.hasNoProfanities]), 126 oldforms.LargeTextField(field_name="comment", max length=3000, is_required=True,126 oldforms.LargeTextField(field_name="comment", max_length=3000, is_required=True, 127 127 validator_list=[self.hasNoProfanities]), 128 128 ) 129 129 -
django/contrib/contenttypes/models.py
21 21 return ct 22 22 23 23 class ContentType(models.Model): 24 name = models.CharField(max length=100)25 app_label = models.CharField(max length=100)26 model = models.CharField(_('python model class name'), max length=100)24 name = models.CharField(max_length=100) 25 app_label = models.CharField(max_length=100) 26 model = models.CharField(_('python model class name'), max_length=100) 27 27 objects = ContentTypeManager() 28 28 class Meta: 29 29 verbose_name = _('content type') -
django/contrib/flatpages/models.py
4 4 from django.utils.translation import gettext_lazy as _ 5 5 6 6 class FlatPage(models.Model): 7 url = models.CharField(_('URL'), max length=100, validator_list=[validators.isAlphaNumericURL],7 url = models.CharField(_('URL'), max_length=100, validator_list=[validators.isAlphaNumericURL], 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
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
48 48 the sessions documentation that is shipped with Django (also available 49 49 on the Django website). 50 50 """ 51 session_key = models.CharField(_('session key'), max length=40, primary_key=True)51 session_key = models.CharField(_('session key'), max_length=40, primary_key=True) 52 52 session_data = models.TextField(_('session data')) 53 53 expire_date = models.DateTimeField(_('expire date')) 54 54 objects = SessionManager() -
django/contrib/sites/models.py
7 7 return self.get(pk=settings.SITE_ID) 8 8 9 9 class Site(models.Model): 10 domain = models.CharField(_('domain name'), max length=100)11 name = models.CharField(_('display name'), max length=50)10 domain = models.CharField(_('domain name'), max_length=100) 11 name = models.CharField(_('display name'), max_length=50) 12 12 objects = SiteManager() 13 13 class Meta: 14 14 db_table = 'django_site' -
django/core/management.py
800 800 field_type, new_params = field_type 801 801 extra_params.update(new_params) 802 802 803 # Add max length for all CharFields.803 # Add max_length for all CharFields. 804 804 if field_type == 'CharField' and row[3]: 805 extra_params['max length'] = row[3]805 extra_params['max_length'] = row[3] 806 806 807 807 if field_type == 'FloatField': 808 808 extra_params['max_digits'] = row[4] … … 877 877 for f in opts.fields: 878 878 if f.name == 'id' and not f.primary_key and opts.pk.name == 'id': 879 879 e.add(opts, '"%s": You can\'t use "id" as a field name, because each model automatically gets an "id" field if none of the fields have primary_key=True. You need to either remove/rename your "id" field or add primary_key=True to a field.' % f.name) 880 if isinstance(f, models.CharField) and f.max length in (None, 0):881 e.add(opts, '"%s": CharFields require a "max length" attribute.' % f.name)880 if isinstance(f, models.CharField) and f.max_length in (None, 0): 881 e.add(opts, '"%s": CharFields require a "max_length" attribute.' % f.name) 882 882 if isinstance(f, models.FloatField): 883 883 if f.decimal_places is None: 884 884 e.add(opts, '"%s": FloatFields require a "decimal_places" attribute.' % f.name) … … 903 903 if f.db_index not in (None, True, False): 904 904 e.add(opts, '"%s": "db_index" should be either None, True or False.' % f.name) 905 905 906 # Check that max length <= 255 if using older MySQL versions.906 # Check that max_length <= 255 if using older MySQL versions. 907 907 if settings.DATABASE_ENGINE == 'mysql': 908 908 db_version = connection.get_server_version() 909 if db_version < (5, 0, 3) and isinstance(f, (models.CharField, models.CommaSeparatedIntegerField, models.SlugField)) and f.max length > 255:910 e.add(opts, '"%s": %s cannot have a "max length" greater than 255 when you are using a version of MySQL prior to 5.0.3 (you are using %s).' % (f.name, f.__class__.__name__, '.'.join([str(n) for n in db_version[:3]])))909 if db_version < (5, 0, 3) and isinstance(f, (models.CharField, models.CommaSeparatedIntegerField, models.SlugField)) and f.max_length > 255: 910 e.add(opts, '"%s": %s cannot have a "max_length" greater than 255 when you are using a version of MySQL prior to 5.0.3 (you are using %s).' % (f.name, f.__class__.__name__, '.'.join([str(n) for n in db_version[:3]]))) 911 911 912 912 # Check to see if the related field will clash with any 913 913 # existing fields, m2m fields, m2m related objects or related objects … … 1142 1142 data_types = get_creation_module().DATA_TYPES 1143 1143 fields = ( 1144 1144 # "key" is a reserved word in MySQL, so use "cache_key" instead. 1145 models.CharField(name='cache_key', max length=255, unique=True, primary_key=True),1145 models.CharField(name='cache_key', max_length=255, unique=True, primary_key=True), 1146 1146 models.TextField(name='value'), 1147 1147 models.DateTimeField(name='expires', db_index=True), 1148 1148 ) -
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 'FileField': 'varchar(100)', … … 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
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 'FileField': 'varchar(100)', … … 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
1 1 DATA_TYPES = { 2 2 'AutoField': 'number(38)', 3 3 'BooleanField': 'number(1)', 4 'CharField': 'varchar2(%(max length)s)',5 'CommaSeparatedIntegerField': 'varchar2(%(max length)s)',4 'CharField': 'varchar2(%(max_length)s)', 5 'CommaSeparatedIntegerField': 'varchar2(%(max_length)s)', 6 6 'DateField': 'date', 7 7 'DateTimeField': 'date', 8 8 'FileField': 'varchar2(100)', -
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 'FileField': 'varchar(100)', … … 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
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 'FileField': 'varchar(100)', … … 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
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
41 41 return 42 42 raise validators.ValidationError, gettext("%(optname)s with this %(fieldname)s already exists.") % {'optname': capfirst(opts.verbose_name), 'fieldname': f.verbose_name} 43 43 44 # Methods for legacy maxlength support. 45 def get_maxlength(self): 46 return self.max_length 47 def set_maxlength(self, value): 48 self.max_length = value 49 def legacy_maxlength(max_length, maxlength): 50 if maxlength is not None: 51 if max_length is not None: 52 raise TypeError, 'field can not take both the max_length argument and the legacy maxlength argument' 53 max_length = maxlength 54 return max_length 55 def legacy_maxlength_kwargs(kwargs): 56 "Passed a dictionary, replaces maxlength with max_length" 57 if kwargs.has_key('maxlength'): 58 kwargs['max_length'] = legacy_maxlength(max_length=kwargs.get('max_length', None), maxlength=kwargs['maxlength']) 59 del kwargs['maxlength'] 60 return kwargs 61 44 62 # A guide to Field parameters: 45 63 # 46 64 # * name: The name of the field specifed in the model. … … 66 84 creation_counter = 0 67 85 68 86 def __init__(self, verbose_name=None, name=None, primary_key=False, 69 max length=None, unique=False, blank=False, null=False, db_index=False,87 max_length=None, unique=False, blank=False, null=False, db_index=False, 70 88 core=False, rel=None, default=NOT_PROVIDED, editable=True, 71 89 prepopulate_from=None, unique_for_date=None, unique_for_month=None, 72 90 unique_for_year=None, validator_list=None, choices=None, radio_admin=None, 73 help_text='', db_column=None ):91 help_text='', db_column=None, maxlength=None): 74 92 self.name = name 75 93 self.verbose_name = verbose_name 76 94 self.primary_key = primary_key 77 self.maxlength, self.unique = maxlength, unique 95 # Fields now use max_length, but still support the legacy maxlength argument. 96 self.max_length = legacy_maxlength(max_length=max_length, maxlength=maxlength) 97 self.unique = unique 78 98 self.blank, self.null = blank, null 79 99 self.core, self.rel, self.default = core, rel, default 80 100 self.editable = editable … … 94 114 self.creation_counter = Field.creation_counter 95 115 Field.creation_counter += 1 96 116 117 # Support accessing and setting to the legacy maxlength argument. 118 maxlength = property(get_maxlength, set_maxlength) 119 97 120 def __cmp__(self, other): 98 121 # This is needed because bisect does not take a comparison function. 99 122 return cmp(self.creation_counter, other.creation_counter) … … 202 225 203 226 def prepare_field_objs_and_params(self, manipulator, name_prefix): 204 227 params = {'validator_list': self.validator_list[:]} 205 if self.max length and not self.choices: # Don't give SelectFields a maxlength parameter.206 params['max length'] = self.maxlength228 if self.max_length and not self.choices: # Don't give SelectFields a max_length parameter. 229 params['max_length'] = self.max_length 207 230 208 231 if self.choices: 209 232 if self.radio_admin: … … 347 370 class AutoField(Field): 348 371 empty_strings_allowed = False 349 372 def __init__(self, *args, **kwargs): 373 kwargs = legacy_maxlength_kwargs(kwargs) 350 374 assert kwargs.get('primary_key', False) is True, "%ss must have primary_key=True." % self.__class__.__name__ 351 375 kwargs['blank'] = True 352 376 Field.__init__(self, *args, **kwargs) … … 385 409 386 410 class BooleanField(Field): 387 411 def __init__(self, *args, **kwargs): 412 kwargs = legacy_maxlength_kwargs(kwargs) 388 413 kwargs['blank'] = True 389 414 Field.__init__(self, *args, **kwargs) 390 415 … … 417 442 return str(value) 418 443 419 444 def formfield(self, **kwargs): 420 defaults = {'max_length': self.max length, 'required': not self.blank, 'label': capfirst(self.verbose_name)}445 defaults = {'max_length': self.max_length, 'required': not self.blank, 'label': capfirst(self.verbose_name)} 421 446 defaults.update(kwargs) 422 447 return forms.CharField(**defaults) 423 448 … … 562 587 563 588 class EmailField(CharField): 564 589 def __init__(self, *args, **kwargs): 565 kwargs['maxlength'] = 75 590 kwargs = legacy_maxlength_kwargs(kwargs) 591 kwargs['max_length'] = 75 566 592 CharField.__init__(self, *args, **kwargs) 567 593 568 594 def get_internal_type(self): … … 718 744 719 745 class IPAddressField(Field): 720 746 def __init__(self, *args, **kwargs): 721 kwargs['maxlength'] = 15 747 kwargs = legacy_maxlength_kwargs(kwargs) 748 kwargs['max_length'] = 15 722 749 Field.__init__(self, *args, **kwargs) 723 750 724 751 def get_manipulator_field_objs(self): … … 729 756 730 757 class NullBooleanField(Field): 731 758 def __init__(self, *args, **kwargs): 759 kwargs = legacy_maxlength_kwargs(kwargs) 732 760 kwargs['null'] = True 733 761 Field.__init__(self, *args, **kwargs) 734 762 … … 752 780 753 781 class SlugField(Field): 754 782 def __init__(self, *args, **kwargs): 755 kwargs['maxlength'] = kwargs.get('maxlength', 50) 783 kwargs = legacy_maxlength_kwargs(kwargs) 784 kwargs['max_length'] = kwargs.get('max_length', 50) 756 785 kwargs.setdefault('validator_list', []).append(validators.isSlug) 757 786 # Set db_index=True unless it's been set manually. 758 787 if not kwargs.has_key('db_index'): … … 822 851 823 852 class URLField(CharField): 824 853 def __init__(self, verbose_name=None, name=None, verify_exists=True, **kwargs): 825 kwargs['max length'] = kwargs.get('maxlength', 200)854 kwargs['max_length'] = kwargs.get('max_length', 200) 826 855 if verify_exists: 827 856 kwargs.setdefault('validator_list', []).append(validators.isExistingURL) 828 857 self.verify_exists = verify_exists -
django/newforms/fields.py
102 102 103 103 def widget_attrs(self, widget): 104 104 if self.max_length is not None and isinstance(widget, (TextInput, PasswordInput)): 105 # The HTML attribute is maxlength, not max_length. 105 106 return {'maxlength': str(self.max_length)} 106 107 107 108 class IntegerField(Field): -
django/oldforms/__init__.py
371 371 # GENERIC WIDGETS # 372 372 #################### 373 373 374 # Methods for legacy maxlength support. 375 def get_maxlength(self): 376 return self.max_length 377 def set_maxlength(self, value): 378 self.max_length = value 379 def legacy_maxlength(max_length, maxlength, has_default=False): 380 """ 381 Override new max_length attribute with legacy maxlength if it has been given. 382 An error will be raised if both attributes are given. To avoid this (which the 383 normal case is that new max_length has been given a default value) set 384 has_default to True. 385 """ 386 if maxlength is not None: 387 if max_length is not None and not has_default: 388 raise TypeError, 'field can not take both the max_length argument and the legacy maxlength argument' 389 max_length = maxlength 390 return max_length 391 374 392 class TextField(FormField): 375 393 input_type = "text" 376 def __init__(self, field_name, length=30, max length=None, is_required=False, validator_list=None, member_name=None):394 def __init__(self, field_name, length=30, max_length=None, is_required=False, validator_list=None, member_name=None, maxlength=None): 377 395 if validator_list is None: validator_list = [] 378 396 self.field_name = field_name 379 self.length, self.maxlength = length, maxlength 397 self.length = length 398 # Fields now use max_length, but still support the legacy maxlength argument. 399 self.max_length = legacy_maxlength(max_length=max_length, maxlength=maxlength) 380 400 self.is_required = is_required 381 401 self.validator_list = [self.isValidLength, self.hasNoNewlines] + validator_list 382 402 if member_name != None: 383 403 self.member_name = member_name 384 404 405 # Support accessing and setting the legacy maxlength argument. 406 maxlength = property(get_maxlength, set_maxlength) 407 385 408 def isValidLength(self, data, form): 386 if data and self.max length and len(data.decode(settings.DEFAULT_CHARSET)) > self.maxlength:409 if data and self.max_length and len(data.decode(settings.DEFAULT_CHARSET)) > self.max_length: 387 410 raise validators.ValidationError, ngettext("Ensure your text is less than %s character.", 388 "Ensure your text is less than %s characters.", self.max length) % self.maxlength411 "Ensure your text is less than %s characters.", self.max_length) % self.max_length 389 412 390 413 def hasNoNewlines(self, data, form): 391 414 if data and '\n' in data: … … 394 417 def render(self, data): 395 418 if data is None: 396 419 data = '' 397 max length = ''398 if self.max length:399 max length = 'maxlength="%s" ' % self.maxlength420 max_length = '' 421 if self.max_length: 422 max_length = 'maxlength="%s" ' % self.max_length 400 423 if isinstance(data, unicode): 401 424 data = data.encode(settings.DEFAULT_CHARSET) 402 425 return '<input type="%s" id="%s" class="v%s%s" name="%s" size="%s" value="%s" %s/>' % \ 403 426 (self.input_type, self.get_id(), self.__class__.__name__, self.is_required and ' required' or '', 404 self.field_name, self.length, escape(data), max length)427 self.field_name, self.length, escape(data), max_length) 405 428 406 429 def html2python(data): 407 430 return data … … 411 434 input_type = "password" 412 435 413 436 class LargeTextField(TextField): 414 def __init__(self, field_name, rows=10, cols=40, is_required=False, validator_list=None, maxlength=None): 437 def __init__(self, field_name, rows=10, cols=40, is_required=False, validator_list=None, max_length=None, maxlength=None): 438 max_length = legacy_maxlength(max_length=max_length, maxlength=maxlength) 415 439 if validator_list is None: validator_list = [] 416 440 self.field_name = field_name 417 441 self.rows, self.cols, self.is_required = rows, cols, is_required 418 442 self.validator_list = validator_list[:] 419 if max length:443 if max_length: 420 444 self.validator_list.append(self.isValidLength) 421 self.max length = maxlength445 self.max_length = max_length 422 446 423 447 def render(self, data): 424 448 if data is None: … … 695 719 #################### 696 720 697 721 class IntegerField(TextField): 698 def __init__(self, field_name, length=10, maxlength=None, is_required=False, validator_list=None, member_name=None): 722 def __init__(self, field_name, length=10, max_length=None, is_required=False, validator_list=None, member_name=None, maxlength=None): 723 max_length = legacy_maxlength(max_length=max_length, maxlength=maxlength) 699 724 if validator_list is None: validator_list = [] 700 725 validator_list = [self.isInteger] + validator_list 701 726 if member_name is not None: 702 727 self.member_name = member_name 703 TextField.__init__(self, field_name, length, max length, is_required, validator_list)728 TextField.__init__(self, field_name, length, max_length, is_required, validator_list) 704 729 705 730 def isInteger(self, field_data, all_data): 706 731 try: … … 715 740 html2python = staticmethod(html2python) 716 741 717 742 class SmallIntegerField(IntegerField): 718 def __init__(self, field_name, length=5, maxlength=5, is_required=False, validator_list=None): 743 def __init__(self, field_name, length=5, max_length=5, is_required=False, validator_list=None, maxlength=None): 744 max_length = legacy_maxlength(max_length=max_length, maxlength=maxlength, has_default=True) 719 745 if validator_list is None: validator_list = [] 720 746 validator_list = [self.isSmallInteger] + validator_list 721 IntegerField.__init__(self, field_name, length, max length, is_required, validator_list)747 IntegerField.__init__(self, field_name, length, max_length, is_required, validator_list) 722 748 723 749 def isSmallInteger(self, field_data, all_data): 724 750 if not -32768 <= int(field_data) <= 32767: 725 751 raise validators.CriticalValidationError, gettext("Enter a whole number between -32,768 and 32,767.") 726 752 727 753 class PositiveIntegerField(IntegerField): 728 def __init__(self, field_name, length=10, maxlength=None, is_required=False, validator_list=None): 754 def __init__(self, field_name, length=10, max_length=None, is_required=False, validator_list=None, maxlength=None): 755 max_length = legacy_maxlength(max_length=max_length, maxlength=maxlength) 729 756 if validator_list is None: validator_list = [] 730 757 validator_list = [self.isPositive] + validator_list 731 IntegerField.__init__(self, field_name, length, max length, is_required, validator_list)758 IntegerField.__init__(self, field_name, length, max_length, is_required, validator_list) 732 759 733 760 def isPositive(self, field_data, all_data): 734 761 if int(field_data) < 0: 735 762 raise validators.CriticalValidationError, gettext("Enter a positive number.") 736 763 737 764 class PositiveSmallIntegerField(IntegerField): 738 def __init__(self, field_name, length=5, maxlength=None, is_required=False, validator_list=None): 765 def __init__(self, field_name, length=5, max_length=None, is_required=False, validator_list=None, maxlength=None): 766 max_length = legacy_maxlength(max_length=max_length, maxlength=maxlength) 739 767 if validator_list is None: validator_list = [] 740 768 validator_list = [self.isPositiveSmall] + validator_list 741 IntegerField.__init__(self, field_name, length, max length, is_required, validator_list)769 IntegerField.__init__(self, field_name, length, max_length, is_required, validator_list) 742 770 743 771 def isPositiveSmall(self, field_data, all_data): 744 772 if not 0 <= int(field_data) <= 32767: … … 771 799 class DatetimeField(TextField): 772 800 """A FormField that automatically converts its data to a datetime.datetime object. 773 801 The data should be in the format YYYY-MM-DD HH:MM:SS.""" 774 def __init__(self, field_name, length=30, maxlength=None, is_required=False, validator_list=None): 802 def __init__(self, field_name, length=30, max_length=None, is_required=False, validator_list=None, maxlength=None): 803 max_length = legacy_maxlength(max_length=max_length, maxlength=maxlength) 775 804 if validator_list is None: validator_list = [] 776 805 self.field_name = field_name 777 self.length, self.max length = length, maxlength806 self.length, self.max_length = length, max_length 778 807 self.is_required = is_required 779 808 self.validator_list = [validators.isValidANSIDatetime] + validator_list 780 809 … … 801 830 def __init__(self, field_name, is_required=False, validator_list=None): 802 831 if validator_list is None: validator_list = [] 803 832 validator_list = [self.isValidDate] + validator_list 804 TextField.__init__(self, field_name, length=10, max length=10,833 TextField.__init__(self, field_name, length=10, max_length=10, 805 834 is_required=is_required, validator_list=validator_list) 806 835 807 836 def isValidDate(self, field_data, all_data): … … 826 855 def __init__(self, field_name, is_required=False, validator_list=None): 827 856 if validator_list is None: validator_list = [] 828 857 validator_list = [self.isValidTime] + validator_list 829 TextField.__init__(self, field_name, length=8, max length=8,858 TextField.__init__(self, field_name, length=8, max_length=8, 830 859 is_required=is_required, validator_list=validator_list) 831 860 832 861 def isValidTime(self, field_data, all_data): … … 858 887 859 888 class EmailField(TextField): 860 889 "A convenience FormField for validating e-mail addresses" 861 def __init__(self, field_name, length=50, maxlength=75, is_required=False, validator_list=None): 890 def __init__(self, field_name, length=50, max_length=75, is_required=False, validator_list=None, maxlength=None): 891 max_length = legacy_maxlength(max_length=max_length, maxlength=maxlength, has_default=True) 862 892 if validator_list is None: validator_list = [] 863 893 validator_list = [self.isValidEmail] + validator_list 864 TextField.__init__(self, field_name, length, max length=maxlength,894 TextField.__init__(self, field_name, length, max_length=max_length, 865 895 is_required=is_required, validator_list=validator_list) 866 896 867 897 def isValidEmail(self, field_data, all_data): … … 872 902 873 903 class URLField(TextField): 874 904 "A convenience FormField for validating URLs" 875 def __init__(self, field_name, length=50, maxlength=200, is_required=False, validator_list=None): 905 def __init__(self, field_name, length=50, max_length=200, is_required=False, validator_list=None, maxlength=None): 906 max_length = legacy_maxlength(max_length=max_length, maxlength=maxlength, has_default=True) 876 907 if validator_list is None: validator_list = [] 877 908 validator_list = [self.isValidURL] + validator_list 878 TextField.__init__(self, field_name, length=length, max length=maxlength,909 TextField.__init__(self, field_name, length=length, max_length=max_length, 879 910 is_required=is_required, validator_list=validator_list) 880 911 881 912 def isValidURL(self, field_data, all_data): … … 885 916 raise validators.CriticalValidationError, e.messages 886 917 887 918 class IPAddressField(TextField): 888 def __init__(self, field_name, length=15, maxlength=15, is_required=False, validator_list=None): 919 def __init__(self, field_name, length=15, max_length=15, is_required=False, validator_list=None, maxlength=None): 920 max_length = legacy_maxlength(max_length=max_length, maxlength=maxlength, has_default=True) 889 921 if validator_list is None: validator_list = [] 890 922 validator_list = [self.isValidIPAddress] + validator_list 891 TextField.__init__(self, field_name, length=length, max length=maxlength,923 TextField.__init__(self, field_name, length=length, max_length=max_length, 892 924 is_required=is_required, validator_list=validator_list) 893 925 894 926 def isValidIPAddress(self, field_data, all_data): … … 934 966 def __init__(self, field_name, is_required=False, validator_list=None): 935 967 if validator_list is None: validator_list = [] 936 968 validator_list = [self.isValidPhone] + validator_list 937 TextField.__init__(self, field_name, length=12, max length=12,969 TextField.__init__(self, field_name, length=12, max_length=12, 938 970 is_required=is_required, validator_list=validator_list) 939 971 940 972 def isValidPhone(self, field_data, all_data): … … 948 980 def __init__(self, field_name, is_required=False, validator_list=None): 949 981 if validator_list is None: validator_list = [] 950 982 validator_list = [self.isValidUSState] + validator_list 951 TextField.__init__(self, field_name, length=2, max length=2,983 TextField.__init__(self, field_name, length=2, max_length=2, 952 984 is_required=is_required, validator_list=validator_list) 953 985 954 986 def isValidUSState(self, field_data, all_data): … … 963 995 964 996 class CommaSeparatedIntegerField(TextField): 965 997 "A convenience FormField for validating comma-separated integer fields" 966 def __init__(self, field_name, maxlength=None, is_required=False, validator_list=None): 998 def __init__(self, field_name, max_length=None, is_required=False, validator_list=None, maxlength=None): 999 max_length = legacy_maxlength(max_length=max_length, maxlength=maxlength) 967 1000 if validator_list is None: validator_list = [] 968 1001 validator_list = [self.isCommaSeparatedIntegerList] + validator_list 969 TextField.__init__(self, field_name, length=20, max length=maxlength,1002 TextField.__init__(self, field_name, length=20, max_length=max_length, 970 1003 is_required=is_required, validator_list=validator_list) 971 1004 972 1005 def isCommaSeparatedIntegerList(self, field_data, all_data): -
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 __str__(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 __str__(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) … … 1633 1633 ('F', 'Female'), 1634 1634 ) 1635 1635 class Person(models.Model): 1636 name = models.CharField(max length=20)1637 gender = models.CharField(max length=1, choices=GENDER_CHOICES)1636 name = models.CharField(max_length=20) 1637 gender = models.CharField(max_length=1, choices=GENDER_CHOICES) 1638 1638 1639 1639 ...each ``Person`` instance will have a ``get_gender_display()`` method. Example:: 1640 1640 -
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
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`` … … 188 192 ~~~~~~~~~~~~~~ 189 193 190 194 A ``CharField`` that checks that the value is a valid e-mail address. 191 This doesn't accept ``max length``; its ``maxlength`` is automatically set to195 This doesn't accept ``max_length``; its ``max_length`` is automatically set to 192 196 75. 193 197 194 198 ``FileField`` … … 362 366 containing only letters, numbers, underscores or hyphens. They're generally 363 367 used in URLs. 364 368 365 In the Django development version, you can specify ``max length``. If366 ``max length`` is not specified, Django will use a default length of 50. In369 In the Django development version, you can specify ``max_length``. If 370 ``max_length`` is not specified, Django will use a default length of 50. In 367 371 previous Django versions, there's no way to override the length of 50. 368 372 369 373 Implies ``db_index=True``. … … 487 491 ('M', 'Male'), 488 492 ('F', 'Female'), 489 493 ) 490 gender = models.CharField(max length=1, choices=GENDER_CHOICES)494 gender = models.CharField(max_length=1, choices=GENDER_CHOICES) 491 495 492 496 or outside your model class altogether:: 493 497 … … 496 500 ('F', 'Female'), 497 501 ) 498 502 class Foo(models.Model): 499 gender = models.CharField(max length=1, choices=GENDER_CHOICES)503 gender = models.CharField(max_length=1, choices=GENDER_CHOICES) 500 504 501 505 Finally, note that choices can be any iterable object -- not necessarily a 502 506 list or tuple. This lets you construct choices dynamically. But if you find … … 633 637 634 638 In this example, the verbose name is ``"Person's first name"``:: 635 639 636 first_name = models.CharField("Person's first name", max length=30)640 first_name = models.CharField("Person's first name", max_length=30) 637 641 638 642 In this example, the verbose name is ``"first name"``:: 639 643 640 first_name = models.CharField(max length=30)644 first_name = models.CharField(max_length=30) 641 645 642 646 ``ForeignKey``, ``ManyToManyField`` and ``OneToOneField`` require the first 643 647 argument to be a model class, so use the ``verbose_name`` keyword argument:: … … 918 922 Give your model metadata by using an inner ``class Meta``, like so:: 919 923 920 924 class Foo(models.Model): 921 bar = models.CharField(max length=30)925 bar = models.CharField(max_length=30) 922 926 923 927 class Meta: 924 928 # ... … … 1084 1088 inner ``"class Admin"``, like so:: 1085 1089 1086 1090 class Person(models.Model): 1087 first_name = models.CharField(max length=30)1088 last_name = models.CharField(max length=30)1091 first_name = models.CharField(max_length=30) 1092 last_name = models.CharField(max_length=30) 1089 1093 1090 1094 class Admin: 1091 1095 # Admin options go here … … 1240 1244 Here's a full example model:: 1241 1245 1242 1246 class Person(models.Model): 1243 name = models.CharField(max length=50)1247 name = models.CharField(max_length=50) 1244 1248 birthday = models.DateField() 1245 1249 1246 1250 class Admin: … … 1257 1261 Here's a full example model:: 1258 1262 1259 1263 class Person(models.Model): 1260 first_name = models.CharField(max length=50)1261 last_name = models.CharField(max length=50)1262 color_code = models.CharField(max length=6)1264 first_name = models.CharField(max_length=50) 1265 last_name = models.CharField(max_length=50) 1266 color_code = models.CharField(max_length=6) 1263 1267 1264 1268 class Admin: 1265 1269 list_display = ('first_name', 'last_name', 'colored_name') … … 1275 1279 Here's a full example model:: 1276 1280 1277 1281 class Person(models.Model): 1278 first_name = models.CharField(max length=50)1282 first_name = models.CharField(max_length=50) 1279 1283 birthday = models.DateField() 1280 1284 1281 1285 class Admin: … … 1530 1534 return result_list 1531 1535 1532 1536 class OpinionPoll(models.Model): 1533 question = models.CharField(max length=200)1537 question = models.CharField(max_length=200) 1534 1538 poll_date = models.DateField() 1535 1539 objects = PollManager() 1536 1540 1537 1541 class Response(models.Model): 1538 1542 poll = models.ForeignKey(Poll) 1539 person_name = models.CharField(max length=50)1543 person_name = models.CharField(max_length=50) 1540 1544 response = models.TextField() 1541 1545 1542 1546 With this example, you'd use ``OpinionPoll.objects.with_counts()`` to return … … 1552 1556 example, using this model:: 1553 1557 1554 1558 class Book(models.Model): 1555 title = models.CharField(max length=100)1556 author = models.CharField(max length=50)1559 title = models.CharField(max_length=100) 1560 author = models.CharField(max_length=50) 1557 1561 1558 1562 ...the statement ``Book.objects.all()`` will return all books in the database. 1559 1563 … … 1571 1575 1572 1576 # Then hook it into the Book model explicitly. 1573 1577 class Book(models.Model): 1574 title = models.CharField(max length=100)1575 author = models.CharField(max length=50)1578 title = models.CharField(max_length=100) 1579 author = models.CharField(max_length=50) 1576 1580 1577 1581 objects = models.Manager() # The default manager. 1578 1582 dahl_objects = DahlBookManager() # The Dahl-specific manager. … … 1605 1609 return super(FemaleManager, self).get_query_set().filter(sex='F') 1606 1610 1607 1611 class Person(models.Model): 1608 first_name = models.CharField(max length=50)1609 last_name = models.CharField(max length=50)1610 sex = models.CharField(max length=1, choices=(('M', 'Male'), ('F', 'Female')))1612 first_name = models.CharField(max_length=50) 1613 last_name = models.CharField(max_length=50) 1614 sex = models.CharField(max_length=1, choices=(('M', 'Male'), ('F', 'Female'))) 1611 1615 people = models.Manager() 1612 1616 men = MaleManager() 1613 1617 women = FemaleManager() … … 1637 1641 For example, this model has a few custom methods:: 1638 1642 1639 1643 class Person(models.Model): 1640 first_name = models.CharField(max length=50)1641 last_name = models.CharField(max length=50)1644 first_name = models.CharField(max_length=50) 1645 last_name = models.CharField(max_length=50) 1642 1646 birth_date = models.DateField() 1643 address = models.CharField(max length=100)1644 city = models.CharField(max length=50)1647 address = models.CharField(max_length=100) 1648 city = models.CharField(max_length=50) 1645 1649 state = models.USStateField() # Yes, this is America-centric... 1646 1650 1647 1651 def baby_boomer_status(self): … … 1681 1685 For example:: 1682 1686 1683 1687 class Person(models.Model): 1684 first_name = models.CharField(max length=50)1685 last_name = models.CharField(max length=50)1688 first_name = models.CharField(max_length=50) 1689 last_name = models.CharField(max_length=50) 1686 1690 1687 1691 def __str__(self): 1688 1692 return '%s %s' % (self.first_name, self.last_name) … … 1764 1768 to happen whenever you save an object. For example:: 1765 1769 1766 1770 class Blog(models.Model): 1767 name = models.CharField(max length=100)1771 name = models.CharField(max_length=100) 1768 1772 tagline = models.TextField() 1769 1773 1770 1774 def save(self): … … 1775 1779 You can also prevent saving:: 1776 1780 1777 1781 class Blog(models.Model): 1778 name = models.CharField(max length=100)1782 name = models.CharField(max_length=100) 1779 1783 tagline = models.TextField() 1780 1784 1781 1785 def save(self): -
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 __str__(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
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
71 71 'The cat says "meow"' 72 72 """ 73 73 74 name = models.CharField(max length=20)75 sound = models.CharField(max length=20)74 name = models.CharField(max_length=20) 75 sound = models.CharField(max_length=20) 76 76 77 77 def speak(self): 78 78 return 'The %s says "%s"' % (self.name, self.sound) -
docs/tutorial01.txt
233 233 from django.db import models 234 234 235 235 class Poll(models.Model): 236 question = models.CharField(max length=200)236 question = models.CharField(max_length=200) 237 237 pub_date = models.DateTimeField('date published') 238 238 239 239 class Choice(models.Model): 240 240 poll = models.ForeignKey(Poll) 241 choice = models.CharField(max length=200)241 choice = models.CharField(max_length=200) 242 242 votes = models.IntegerField() 243 243 244 244 The code is straightforward. Each model is represented by a class that … … 261 261 machine-readable name will suffice as its human-readable name. 262 262 263 263 Some ``Field`` classes have required elements. ``CharField``, for example, 264 requires that you give it a ``max length``. That's used not only in the database264 requires that you give it a ``max_length``. That's used not only in the database 265 265 schema, but in validation, as we'll soon see. 266 266 267 267 Finally, note a relationship is defined, using ``models.ForeignKey``. That tells -
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
7 7 from django.db import models 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 13 13 class Meta: -
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 __str__(self): 24 24 return self.name -
tests/modeltests/custom_columns/models.py
9 9 from django.db import models 10 10 11 11 class Person(models.Model): 12 first_name = models.CharField(max length=30, db_column='firstname')13 last_name = models.CharField(max length=30, db_column='last')12 first_name = models.CharField(max_length=30, db_column='firstname') 13 last_name = models.CharField(max_length=30, db_column='last') 14 14 15 15 def __str__(self): 16 16 return '%s %s' % (self.first_name, self.last_name) -
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
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 __str__(self): -
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 "%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
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 __str__(self): -
tests/modeltests/generic_relations/models.py
27 27 return self.tag 28 28 29 29 class Animal(models.Model): 30 common_name = models.CharField(max length=150)31 latin_name = models.CharField(max length=150)30 common_name = models.CharField(max_length=150) 31 latin_name = models.CharField(max_length=150) 32 32 33 33 tags = models.GenericRelation(TaggedItem) 34 34 … … 36 36 return self.common_name 37 37 38 38 class Vegetable(models.Model): 39 name = models.CharField(max length=150)39 name = models.CharField(max_length=150) 40 40 is_yucky = models.BooleanField(default=True) 41 41 42 42 tags = models.GenericRelation(TaggedItem) … … 45 45 return self.name 46 46 47 47 class Mineral(models.Model): 48 name = models.CharField(max length=150)48 name = models.CharField(max_length=150) 49 49 hardness = models.PositiveSmallIntegerField() 50 50 51 51 # note the lack of an explicit GenericRelation here... -
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
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 __str__(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
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 __str__(self): -
tests/modeltests/invalid_models/models.py
10 10 charfield = models.CharField() 11 11 floatfield = models.FloatField() 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. … … 97 97 m2m_3 = models.ManyToManyField('self', symmetrical=False) 98 98 m2m_4 = models.ManyToManyField('self', symmetrical=False) 99 99 100 model_errors = """invalid_models.fielderrors: "charfield": CharFields require a "max length" attribute.100 model_errors = """invalid_models.fielderrors: "charfield": CharFields require a "max_length" attribute. 101 101 invalid_models.fielderrors: "floatfield": FloatFields require a "decimal_places" attribute. 102 102 invalid_models.fielderrors: "floatfield": FloatFields require a "max_digits" attribute. 103 103 invalid_models.fielderrors: "filefield": FileFields require an "upload_to" attribute. -
tests/modeltests/lookup/models.py
7 7 from django.db import models 8 8 9 9 class Article(models.Model): 10 headline = models.CharField(max length=100)10 headline = models.CharField(max_length=100) 11 11 pub_date = models.DateTimeField() 12 12 class Meta: 13 13 ordering = ('-pub_date', 'headline') -
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
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 __str__(self): 20 20 return "%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 __str__(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 __str__(self): 35 35 return '%s (%s)' % (self.reporter, self.position) -
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
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_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/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 __str__(self): -
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 __str__(self): 14 14 return "%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
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 __str__(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 __str__(self): -
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 __str__(self): 15 15 return "%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
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 __str__(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
25 25 from django.db import models 26 26 27 27 class Category(models.Model): 28 name = models.CharField(max length=20)29 url = models.CharField('The URL', max length=40)28 name = models.CharField(max_length=20) 29 url = models.CharField('The URL', max_length=40) 30 30 31 31 def __str__(self): 32 32 return self.name 33 33 34 34 class Writer(models.Model): 35 name = models.CharField(max length=50)35 name = models.CharField(max_length=50) 36 36 37 37 def __str__(self): 38 38 return self.name 39 39 40 40 class Article(models.Model): 41 headline = models.CharField(max length=50)41 headline = models.CharField(max_length=50) 42 42 pub_date = models.DateField() 43 43 writer = models.ForeignKey(Writer) 44 44 article = models.TextField() -
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 __str__(self): 14 14 return "%s the place" % self.name -
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
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 __str__(self): 16 16 return "%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 __str__(self): 31 31 return "%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
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
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
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 __str__(self): -
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
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
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 __str__(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 __str__(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
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 __str__(self): 15 15 return "%s %s" % (self.first_name, self.last_name) -
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
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.DateTimeField() 16 16 17 17 def __str__(self): -
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 __str__(self): -
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/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
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/maxlength/tests.py
1 # Test access to max_length while still providing full backwards compatibility 2 # with legacy maxlength attribute. 3 """ 4 #=============================================================================== 5 # Fields 6 #=============================================================================== 7 8 # Set up fields 9 >>> from django.db.models import fields 10 >>> new = fields.Field(max_length=15) 11 >>> old = fields.Field(maxlength=10) 12 13 # Ensure both max_length and legacy maxlength are not able to both be specified 14 >>> fields.Field(maxlength=10, max_length=15) 15 Traceback (most recent call last): 16 ... 17 TypeError: field can not take both the max_length argument and the legacy maxlength argument 18 19 # Test max_length 20 >>> new.max_length 21 15 22 >>> old.max_length 23 10 24 25 # Test accessing maxlength 26 >>> new.maxlength 27 15 28 >>> old.maxlength 29 10 30 31 # Test setting maxlength 32 >>> new.maxlength += 1 33 >>> old.maxlength += 1 34 >>> new.max_length 35 16 36 >>> old.max_length 37 11 38 39 # SlugField __init__ passes through max_length so test that too 40 >>> fields.SlugField('new', max_length=15).max_length 41 15 42 >>> fields.SlugField('empty').max_length 43 50 44 >>> fields.SlugField('old', maxlength=10).max_length 45 10 46 47 #=============================================================================== 48 # (old)forms 49 #=============================================================================== 50 51 >>> from django import oldforms 52 53 # Test max_length attribute 54 55 >>> oldforms.TextField('new', max_length=15).render('') 56 '<input type="text" id="id_new" class="vTextField" name="new" size="30" value="" maxlength="15" />' 57 58 >>> oldforms.IntegerField('new', max_length=15).render('') 59 '<input type="text" id="id_new" class="vIntegerField" name="new" size="10" value="" maxlength="15" />' 60 61 >>> oldforms.SmallIntegerField('new', max_length=15).render('') 62 '<input type="text" id="id_new" class="vSmallIntegerField" name="new" size="5" value="" maxlength="15" />' 63 64 >>> oldforms.PositiveIntegerField('new', max_length=15).render('') 65 '<input type="text" id="id_new" class="vPositiveIntegerField" name="new" size="10" value="" maxlength="15" />' 66 67 >>> oldforms.PositiveSmallIntegerField('new', max_length=15).render('') 68 '<input type="text" id="id_new" class="vPositiveSmallIntegerField" name="new" size="5" value="" maxlength="15" />' 69 70 >>> oldforms.DatetimeField('new', max_length=15).render('') 71 '<input type="text" id="id_new" class="vDatetimeField" name="new" size="30" value="" maxlength="15" />' 72 73 >>> oldforms.EmailField('new', max_length=15).render('') 74 '<input type="text" id="id_new" class="vEmailField" name="new" size="50" value="" maxlength="15" />' 75 >>> oldforms.EmailField('new').render('') 76 '<input type="text" id="id_new" class="vEmailField" name="new" size="50" value="" maxlength="75" />' 77 78 >>> oldforms.URLField('new', max_length=15).render('') 79 '<input type="text" id="id_new" class="vURLField" name="new" size="50" value="" maxlength="15" />' 80 >>> oldforms.URLField('new').render('') 81 '<input type="text" id="id_new" class="vURLField" name="new" size="50" value="" maxlength="200" />' 82 83 >>> oldforms.IPAddressField('new', max_length=15).render('') 84 '<input type="text" id="id_new" class="vIPAddressField" name="new" size="15" value="" maxlength="15" />' 85 >>> oldforms.IPAddressField('new').render('') 86 '<input type="text" id="id_new" class="vIPAddressField" name="new" size="15" value="" maxlength="15" />' 87 88 >>> oldforms.CommaSeparatedIntegerField('new', max_length=15).render('') 89 '<input type="text" id="id_new" class="vCommaSeparatedIntegerField" name="new" size="20" value="" maxlength="15" />' 90 91 >>> 92 93 # Test legacy maxlength attribute 94 95 >>> oldforms.TextField('old', maxlength=10).render('') 96 '<input type="text" id="id_old" class="vTextField" name="old" size="30" value="" maxlength="10" />' 97 98 >>> oldforms.IntegerField('old', maxlength=10).render('') 99 '<input type="text" id="id_old" class="vIntegerField" name="old" size="10" value="" maxlength="10" />' 100 101 >>> oldforms.SmallIntegerField('old', maxlength=10).render('') 102 '<input type="text" id="id_old" class="vSmallIntegerField" name="old" size="5" value="" maxlength="10" />' 103 104 >>> oldforms.PositiveIntegerField('old', maxlength=10).render('') 105 '<input type="text" id="id_old" class="vPositiveIntegerField" name="old" size="10" value="" maxlength="10" />' 106 107 >>> oldforms.PositiveSmallIntegerField('old', maxlength=10).render('') 108 '<input type="text" id="id_old" class="vPositiveSmallIntegerField" name="old" size="5" value="" maxlength="10" />' 109 110 >>> oldforms.DatetimeField('old', maxlength=10).render('') 111 '<input type="text" id="id_old" class="vDatetimeField" name="old" size="30" value="" maxlength="10" />' 112 113 >>> oldforms.EmailField('old', maxlength=10).render('') 114 '<input type="text" id="id_old" class="vEmailField" name="old" size="50" value="" maxlength="10" />' 115 116 >>> oldforms.URLField('old', maxlength=10).render('') 117 '<input type="text" id="id_old" class="vURLField" name="old" size="50" value="" maxlength="10" />' 118 119 >>> oldforms.IPAddressField('old', maxlength=10).render('') 120 '<input type="text" id="id_old" class="vIPAddressField" name="old" size="15" value="" maxlength="10" />' 121 122 >>> oldforms.CommaSeparatedIntegerField('old', maxlength=10).render('') 123 '<input type="text" id="id_old" class="vCommaSeparatedIntegerField" name="old" size="20" value="" maxlength="10" />' 124 """ 125 if __name__ == "__main__": 126 import doctest 127 doctest.testmod() -
tests/regressiontests/maxlength/tests.py
1 # Test access to max_length while still providing full backwards compatibility 2 # with legacy maxlength attribute. 3 """ 4 #=============================================================================== 5 # Fields 6 #=============================================================================== 7 8 # Set up fields 9 >>> from django.db.models import fields 10 >>> new = fields.Field(max_length=15) 11 >>> old = fields.Field(maxlength=10) 12 13 # Ensure both max_length and legacy maxlength are not able to both be specified 14 >>> fields.Field(maxlength=10, max_length=15) 15 Traceback (most recent call last): 16 ... 17 TypeError: field can not take both the max_length argument and the legacy maxlength argument 18 19 # Test max_length 20 >>> new.max_length 21 15 22 >>> old.max_length 23 10 24 25 # Test accessing maxlength 26 >>> new.maxlength 27 15 28 >>> old.maxlength 29 10 30 31 # Test setting maxlength 32 >>> new.maxlength += 1 33 >>> old.maxlength += 1 34 >>> new.max_length 35 16 36 >>> old.max_length 37 11 38 39 # SlugField __init__ passes through max_length so test that too 40 >>> fields.SlugField('new', max_length=15).max_length 41 15 42 >>> fields.SlugField('empty').max_length 43 50 44 >>> fields.SlugField('old', maxlength=10).max_length 45 10 46 47 #=============================================================================== 48 # (old)forms 49 #=============================================================================== 50 51 >>> from django import oldforms 52 53 # Test max_length attribute 54 55 >>> oldforms.TextField('new', max_length=15).render('') 56 '<input type="text" id="id_new" class="vTextField" name="new" size="30" value="" maxlength="15" />' 57 58 >>> oldforms.IntegerField('new', max_length=15).render('') 59 '<input type="text" id="id_new" class="vIntegerField" name="new" size="10" value="" maxlength="15" />' 60 61 >>> oldforms.SmallIntegerField('new', max_length=15).render('') 62 '<input type="text" id="id_new" class="vSmallIntegerField" name="new" size="5" value="" maxlength="15" />' 63 64 >>> oldforms.PositiveIntegerField('new', max_length=15).render('') 65 '<input type="text" id="id_new" class="vPositiveIntegerField" name="new" size="10" value="" maxlength="15" />' 66 67 >>> oldforms.PositiveSmallIntegerField('new', max_length=15).render('') 68 '<input type="text" id="id_new" class="vPositiveSmallIntegerField" name="new" size="5" value="" maxlength="15" />' 69 70 >>> oldforms.DatetimeField('new', max_length=15).render('') 71 '<input type="text" id="id_new" class="vDatetimeField" name="new" size="30" value="" maxlength="15" />' 72 73 >>> oldforms.EmailField('new', max_length=15).render('') 74 '<input type="text" id="id_new" class="vEmailField" name="new" size="50" value="" maxlength="15" />' 75 >>> oldforms.EmailField('new').render('') 76 '<input type="text" id="id_new" class="vEmailField" name="new" size="50" value="" maxlength="75" />' 77 78 >>> oldforms.URLField('new', max_length=15).render('') 79 '<input type="text" id="id_new" class="vURLField" name="new" size="50" value="" maxlength="15" />' 80 >>> oldforms.URLField('new').render('') 81 '<input type="text" id="id_new" class="vURLField" name="new" size="50" value="" maxlength="200" />' 82 83 >>> oldforms.IPAddressField('new', max_length=15).render('') 84 '<input type="text" id="id_new" class="vIPAddressField" name="new" size="15" value="" maxlength="15" />' 85 >>> oldforms.IPAddressField('new').render('') 86 '<input type="text" id="id_new" class="vIPAddressField" name="new" size="15" value="" maxlength="15" />' 87 88 >>> oldforms.CommaSeparatedIntegerField('new', max_length=15).render('') 89 '<input type="text" id="id_new" class="vCommaSeparatedIntegerField" name="new" size="20" value="" maxlength="15" />' 90 91 >>> 92 93 # Test legacy maxlength attribute 94 95 >>> oldforms.TextField('old', maxlength=10).render('') 96 '<input type="text" id="id_old" class="vTextField" name="old" size="30" value="" maxlength="10" />' 97 98 >>> oldforms.IntegerField('old', maxlength=10).render('') 99 '<input type="text" id="id_old" class="vIntegerField" name="old" size="10" value="" maxlength="10" />' 100 101 >>> oldforms.SmallIntegerField('old', maxlength=10).render('') 102 '<input type="text" id="id_old" class="vSmallIntegerField" name="old" size="5" value="" maxlength="10" />' 103 104 >>> oldforms.PositiveIntegerField('old', maxlength=10).render('') 105 '<input type="text" id="id_old" class="vPositiveIntegerField" name="old" size="10" value="" maxlength="10" />' 106 107 >>> oldforms.PositiveSmallIntegerField('old', maxlength=10).render('') 108 '<input type="text" id="id_old" class="vPositiveSmallIntegerField" name="old" size="5" value="" maxlength="10" />' 109 110 >>> oldforms.DatetimeField('old', maxlength=10).render('') 111 '<input type="text" id="id_old" class="vDatetimeField" name="old" size="30" value="" maxlength="10" />' 112 113 >>> oldforms.EmailField('old', maxlength=10).render('') 114 '<input type="text" id="id_old" class="vEmailField" name="old" size="50" value="" maxlength="10" />' 115 116 >>> oldforms.URLField('old', maxlength=10).render('') 117 '<input type="text" id="id_old" class="vURLField" name="old" size="50" value="" maxlength="10" />' 118 119 >>> oldforms.IPAddressField('old', maxlength=10).render('') 120 '<input type="text" id="id_old" class="vIPAddressField" name="old" size="15" value="" maxlength="10" />' 121 122 >>> oldforms.CommaSeparatedIntegerField('old', maxlength=10).render('') 123 '<input type="text" id="id_old" class="vCommaSeparatedIntegerField" name="old" size="20" value="" maxlength="10" />' 124 """ 125 if __name__ == "__main__": 126 import doctest 127 doctest.testmod() -
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 __str__(self): 7 7 return "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 __str__(self): 14 14 return "Choice: %s in poll %s" % (self.choice, self.poll) -
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 __str__(self): 8 8 return "%s the place" % self.name … … 16 16 return "%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 __str__(self): -
tests/regressiontests/string_lookup/models.py
1 1 from django.db import models 2 2 3 3 class Foo(models.Model): 4 name = models.CharField(max length=50)4 name = models.CharField(max_length=50) 5 5 6 6 def __str__(self): 7 7 return "Foo %s" % self.name 8 8 9 9 class Bar(models.Model): 10 name = models.CharField(max length=50)10 name = models.CharField(max_length=50) 11 11 normal = models.ForeignKey(Foo, related_name='normal_foo') 12 12 fwd = models.ForeignKey("Whiz") 13 13 back = models.ForeignKey("Foo") … … 16 16 return "Bar %s" % self.place.name 17 17 18 18 class Whiz(models.Model): 19 name = models.CharField(max length = 50)19 name = models.CharField(max_length = 50) 20 20 21 21 def __str__(self): 22 22 return "Whiz %s" % self.name 23 23 24 24 class Child(models.Model): 25 25 parent = models.OneToOneField('Base') 26 name = models.CharField(max length = 50)26 name = models.CharField(max_length = 50) 27 27 28 28 def __str__(self): 29 29 return "Child %s" % self.name 30 30 31 31 class Base(models.Model): 32 name = models.CharField(max length = 50)32 name = models.CharField(max_length = 50) 33 33 34 34 def __str__(self): 35 35 return "Base %s" % self.name