Ticket #2101: max_length+docs.patch
| File max_length+docs.patch, 107.6 kB (added by Marc Fargas <telenieko@telenieko.com>, 2 years ago) |
|---|
-
django/db/models/fields/__init__.py
old new 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 44 56 # A guide to Field parameters: 45 57 # 46 58 # * name: The name of the field specifed in the model. … … 66 78 creation_counter = 0 67 79 68 80 def __init__(self, verbose_name=None, name=None, primary_key=False, 69 max length=None, unique=False, blank=False, null=False, db_index=False,81 max_length=None, unique=False, blank=False, null=False, db_index=False, 70 82 core=False, rel=None, default=NOT_PROVIDED, editable=True, 71 83 prepopulate_from=None, unique_for_date=None, unique_for_month=None, 72 84 unique_for_year=None, validator_list=None, choices=None, radio_admin=None, 73 help_text='', db_column=None ):85 help_text='', db_column=None, maxlength=None): 74 86 self.name = name 75 87 self.verbose_name = verbose_name 76 88 self.primary_key = primary_key 77 self.maxlength, self.unique = maxlength, unique 89 # Fields now use max_length, but still support the legacy maxlength argument. 90 self.max_length = legacy_maxlength(max_length=max_length, maxlength=maxlength) 91 self.unique = unique 78 92 self.blank, self.null = blank, null 79 93 self.core, self.rel, self.default = core, rel, default 80 94 self.editable = editable … … 94 108 self.creation_counter = Field.creation_counter 95 109 Field.creation_counter += 1 96 110 111 # Support accessing and setting to the legacy maxlength argument. 112 maxlength = property(get_maxlength, set_maxlength) 113 97 114 def __cmp__(self, other): 98 115 # This is needed because bisect does not take a comparison function. 99 116 return cmp(self.creation_counter, other.creation_counter) … … 202 219 203 220 def prepare_field_objs_and_params(self, manipulator, name_prefix): 204 221 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.maxlength222 if self.max_length and not self.choices: # Don't give SelectFields a max_length parameter. 223 params['max_length'] = self.max_length 207 224 208 225 if self.choices: 209 226 if self.radio_admin: … … 417 434 return str(value) 418 435 419 436 def formfield(self, **kwargs): 420 defaults = {'max_length': self.max length, 'required': not self.blank, 'label': capfirst(self.verbose_name)}437 defaults = {'max_length': self.max_length, 'required': not self.blank, 'label': capfirst(self.verbose_name)} 421 438 defaults.update(kwargs) 422 439 return forms.CharField(**defaults) 423 440 … … 562 579 563 580 class EmailField(CharField): 564 581 def __init__(self, *args, **kwargs): 565 kwargs['max length'] = 75582 kwargs['max_length'] = 75 566 583 CharField.__init__(self, *args, **kwargs) 567 584 568 585 def get_internal_type(self): … … 718 735 719 736 class IPAddressField(Field): 720 737 def __init__(self, *args, **kwargs): 721 kwargs['max length'] = 15738 kwargs['max_length'] = 15 722 739 Field.__init__(self, *args, **kwargs) 723 740 724 741 def get_manipulator_field_objs(self): … … 752 769 753 770 class SlugField(Field): 754 771 def __init__(self, *args, **kwargs): 755 kwargs['max length'] = kwargs.get('maxlength', 50)772 kwargs['max_length'] = kwargs.get('max_length', 50) 756 773 kwargs.setdefault('validator_list', []).append(validators.isSlug) 757 774 # Set db_index=True unless it's been set manually. 758 775 if not kwargs.has_key('db_index'): … … 822 839 823 840 class URLField(CharField): 824 841 def __init__(self, verbose_name=None, name=None, verify_exists=True, **kwargs): 825 kwargs['max length'] = kwargs.get('maxlength', 200)842 kwargs['max_length'] = kwargs.get('max_length', 200) 826 843 if verify_exists: 827 844 kwargs.setdefault('validator_list', []).append(validators.isExistingURL) 828 845 self.verify_exists = verify_exists -
django/db/backends/ado_mssql/creation.py
old new 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/postgresql/creation.py
old new 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/introspection.py
old new 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/backends/sqlite3/creation.py
old new 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/mysql/creation.py
old new 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
old new 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/oldforms/__init__.py
old new 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): -
django/core/management.py
old new 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/contrib/redirects/models.py
old new 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/comments/models.py
old new 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
old new 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/sites/models.py
old new 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/contrib/admin/templatetags/admin_modify.py
old new 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/models.py
old new 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/views/doc.py
old new 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/contenttypes/models.py
old new 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/auth/models.py
old new 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/auth/forms.py
old new 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/sessions/models.py
old new 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/flatpages/models.py
old new 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/newforms/fields.py
old new 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): -
tests/modeltests/basic/models.py
old new 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/m2m_recursive/models.py
old new 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/one_to_one/models.py
old new 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 n
