Fixed #231: all fields that should take max_length now do. Thanks, Don Spaulding.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@6378 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
d022e2581d
commit
980fa8b827
1
AUTHORS
1
AUTHORS
|
@ -276,6 +276,7 @@ answer newbie questions, and generally made Django that much better:
|
|||
sopel
|
||||
Leo Soto <leo.soto@gmail.com>
|
||||
Wiliam Alves de Souza <wiliamsouza83@gmail.com>
|
||||
Don Spaulding <donspauldingii@gmail.com>
|
||||
Bjørn Stabell <bjorn@exoweb.net>
|
||||
Georgi Stanojevski <glisha@gmail.com>
|
||||
Vasiliy Stavenko <stavenko@gmail.com>
|
||||
|
|
|
@ -6,10 +6,10 @@ DATA_TYPES = {
|
|||
'DateField': 'smalldatetime',
|
||||
'DateTimeField': 'smalldatetime',
|
||||
'DecimalField': 'numeric(%(max_digits)s, %(decimal_places)s)',
|
||||
'FileField': 'varchar(100)',
|
||||
'FilePathField': 'varchar(100)',
|
||||
'FileField': 'varchar(%(max_length)s)',
|
||||
'FilePathField': 'varchar(%(max_length)s)',
|
||||
'FloatField': 'double precision',
|
||||
'ImageField': 'varchar(100)',
|
||||
'ImageField': 'varchar(%(max_length)s)',
|
||||
'IntegerField': 'int',
|
||||
'IPAddressField': 'char(15)',
|
||||
'NullBooleanField': 'bit',
|
||||
|
|
|
@ -10,10 +10,10 @@ DATA_TYPES = {
|
|||
'DateField': 'date',
|
||||
'DateTimeField': 'datetime',
|
||||
'DecimalField': 'numeric(%(max_digits)s, %(decimal_places)s)',
|
||||
'FileField': 'varchar(100)',
|
||||
'FilePathField': 'varchar(100)',
|
||||
'FileField': 'varchar(%(max_length)s)',
|
||||
'FilePathField': 'varchar(%(max_length)s)',
|
||||
'FloatField': 'double precision',
|
||||
'ImageField': 'varchar(100)',
|
||||
'ImageField': 'varchar(%(max_length)s)',
|
||||
'IntegerField': 'integer',
|
||||
'IPAddressField': 'char(15)',
|
||||
'NullBooleanField': 'bool',
|
||||
|
|
|
@ -10,10 +10,10 @@ DATA_TYPES = {
|
|||
'DateField': 'date',
|
||||
'DateTimeField': 'datetime',
|
||||
'DecimalField': 'numeric(%(max_digits)s, %(decimal_places)s)',
|
||||
'FileField': 'varchar(100)',
|
||||
'FilePathField': 'varchar(100)',
|
||||
'FileField': 'varchar(%(max_length)s)',
|
||||
'FilePathField': 'varchar(%(max_length)s)',
|
||||
'FloatField': 'double precision',
|
||||
'ImageField': 'varchar(100)',
|
||||
'ImageField': 'varchar(%(max_length)s)',
|
||||
'IntegerField': 'integer',
|
||||
'IPAddressField': 'char(15)',
|
||||
'NullBooleanField': 'bool',
|
||||
|
|
|
@ -13,10 +13,10 @@ DATA_TYPES = {
|
|||
'DateField': 'DATE',
|
||||
'DateTimeField': 'TIMESTAMP',
|
||||
'DecimalField': 'NUMBER(%(max_digits)s, %(decimal_places)s)',
|
||||
'FileField': 'NVARCHAR2(100)',
|
||||
'FilePathField': 'NVARCHAR2(100)',
|
||||
'FileField': 'NVARCHAR2(%(max_length)s)',
|
||||
'FilePathField': 'NVARCHAR2(%(max_length)s)',
|
||||
'FloatField': 'DOUBLE PRECISION',
|
||||
'ImageField': 'NVARCHAR2(100)',
|
||||
'ImageField': 'NVARCHAR2(%(max_length)s)',
|
||||
'IntegerField': 'NUMBER(11)',
|
||||
'IPAddressField': 'VARCHAR2(15)',
|
||||
'NullBooleanField': 'NUMBER(1) CHECK ((%(column)s IN (0,1)) OR (%(column)s IS NULL))',
|
||||
|
@ -28,7 +28,7 @@ DATA_TYPES = {
|
|||
'SmallIntegerField': 'NUMBER(11)',
|
||||
'TextField': 'NCLOB',
|
||||
'TimeField': 'TIMESTAMP',
|
||||
'URLField': 'VARCHAR2(200)',
|
||||
'URLField': 'VARCHAR2(%(max_length)s)',
|
||||
'USStateField': 'CHAR(2)',
|
||||
}
|
||||
|
||||
|
|
|
@ -10,10 +10,10 @@ DATA_TYPES = {
|
|||
'DateField': 'date',
|
||||
'DateTimeField': 'timestamp with time zone',
|
||||
'DecimalField': 'numeric(%(max_digits)s, %(decimal_places)s)',
|
||||
'FileField': 'varchar(100)',
|
||||
'FilePathField': 'varchar(100)',
|
||||
'FileField': 'varchar(%(max_length)s)',
|
||||
'FilePathField': 'varchar(%(max_length)s)',
|
||||
'FloatField': 'double precision',
|
||||
'ImageField': 'varchar(100)',
|
||||
'ImageField': 'varchar(%(max_length)s)',
|
||||
'IntegerField': 'integer',
|
||||
'IPAddressField': 'inet',
|
||||
'NullBooleanField': 'boolean',
|
||||
|
|
|
@ -9,10 +9,10 @@ DATA_TYPES = {
|
|||
'DateField': 'date',
|
||||
'DateTimeField': 'datetime',
|
||||
'DecimalField': 'decimal',
|
||||
'FileField': 'varchar(100)',
|
||||
'FilePathField': 'varchar(100)',
|
||||
'FileField': 'varchar(%(max_length)s)',
|
||||
'FilePathField': 'varchar(%(max_length)s)',
|
||||
'FloatField': 'real',
|
||||
'ImageField': 'varchar(100)',
|
||||
'ImageField': 'varchar(%(max_length)s)',
|
||||
'IntegerField': 'integer',
|
||||
'IPAddressField': 'char(15)',
|
||||
'NullBooleanField': 'bool',
|
||||
|
|
|
@ -686,8 +686,7 @@ class DecimalField(Field):
|
|||
|
||||
class EmailField(CharField):
|
||||
def __init__(self, *args, **kwargs):
|
||||
if 'max_length' not in kwargs:
|
||||
kwargs['max_length'] = 75
|
||||
kwargs['max_length'] = kwargs.get('max_length', 75)
|
||||
CharField.__init__(self, *args, **kwargs)
|
||||
|
||||
def get_internal_type(self):
|
||||
|
@ -707,6 +706,7 @@ class EmailField(CharField):
|
|||
class FileField(Field):
|
||||
def __init__(self, verbose_name=None, name=None, upload_to='', **kwargs):
|
||||
self.upload_to = upload_to
|
||||
kwargs['max_length'] = kwargs.get('max_length', 100)
|
||||
Field.__init__(self, verbose_name, name, **kwargs)
|
||||
|
||||
def get_db_prep_save(self, value):
|
||||
|
@ -808,6 +808,7 @@ class FileField(Field):
|
|||
class FilePathField(Field):
|
||||
def __init__(self, verbose_name=None, name=None, path='', match=None, recursive=False, **kwargs):
|
||||
self.path, self.match, self.recursive = path, match, recursive
|
||||
kwargs['max_length'] = kwargs.get('max_length', 100)
|
||||
Field.__init__(self, verbose_name, name, **kwargs)
|
||||
|
||||
def get_manipulator_field_objs(self):
|
||||
|
|
|
@ -447,7 +447,7 @@ class LargeTextField(TextField):
|
|||
self.field_name, self.rows, self.cols, escape(data))
|
||||
|
||||
class HiddenField(FormField):
|
||||
def __init__(self, field_name, is_required=False, validator_list=None):
|
||||
def __init__(self, field_name, is_required=False, validator_list=None, max_length=None):
|
||||
if validator_list is None: validator_list = []
|
||||
self.field_name, self.is_required = field_name, is_required
|
||||
self.validator_list = validator_list[:]
|
||||
|
@ -674,7 +674,7 @@ class CheckboxSelectMultipleField(SelectMultipleField):
|
|||
####################
|
||||
|
||||
class FileUploadField(FormField):
|
||||
def __init__(self, field_name, is_required=False, validator_list=None):
|
||||
def __init__(self, field_name, is_required=False, validator_list=None, max_length=None):
|
||||
if validator_list is None: validator_list = []
|
||||
self.field_name, self.is_required = field_name, is_required
|
||||
self.validator_list = [self.isNonEmptyFile] + validator_list
|
||||
|
@ -946,7 +946,7 @@ class IPAddressField(TextField):
|
|||
|
||||
class FilePathField(SelectField):
|
||||
"A SelectField whose choices are the files in a given directory."
|
||||
def __init__(self, field_name, path, match=None, recursive=False, is_required=False, validator_list=None):
|
||||
def __init__(self, field_name, path, match=None, recursive=False, is_required=False, validator_list=None, max_length=None):
|
||||
import os
|
||||
from django.db.models import BLANK_CHOICE_DASH
|
||||
if match is not None:
|
||||
|
|
|
@ -293,6 +293,12 @@ visiting its URL on your site. Don't allow that.
|
|||
|
||||
.. _`strftime formatting`: http://docs.python.org/lib/module-time.html#l2h-1941
|
||||
|
||||
**New in development version:**
|
||||
|
||||
By default, file fields are created as ``varchar(100)`` database fields. Like
|
||||
other fields, you can change the maximum length using the ``max_length``
|
||||
argument.
|
||||
|
||||
``FilePathField``
|
||||
~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
@ -330,6 +336,12 @@ not the full path. So, this example::
|
|||
because the ``match`` applies to the base filename (``foo.gif`` and
|
||||
``bar.gif``).
|
||||
|
||||
**New in development version:**
|
||||
|
||||
By default, file fields are created as ``varchar(100)`` database fields. Like
|
||||
other fields, you can change the maximum length using the ``max_length``
|
||||
argument.
|
||||
|
||||
``FloatField``
|
||||
~~~~~~~~~~~~~~
|
||||
|
||||
|
@ -361,6 +373,12 @@ Requires the `Python Imaging Library`_.
|
|||
.. _Python Imaging Library: http://www.pythonware.com/products/pil/
|
||||
.. _elsewhere: ../db-api/#get-foo-height-and-get-foo-width
|
||||
|
||||
**New in development version:**
|
||||
|
||||
By default, file fields are created as ``varchar(100)`` database fields. Like
|
||||
other fields, you can change the maximum length using the ``max_length``
|
||||
argument.
|
||||
|
||||
``IntegerField``
|
||||
~~~~~~~~~~~~~~~~
|
||||
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
|
|
@ -0,0 +1,13 @@
|
|||
from django.db import models
|
||||
|
||||
class PersonWithDefaultMaxLengths(models.Model):
|
||||
email = models.EmailField()
|
||||
vcard = models.FileField(upload_to='/tmp')
|
||||
homepage = models.URLField()
|
||||
avatar = models.FilePathField()
|
||||
|
||||
class PersonWithCustomMaxLengths(models.Model):
|
||||
email = models.EmailField(max_length=384)
|
||||
vcard = models.FileField(upload_to='/tmp', max_length=1024)
|
||||
homepage = models.URLField(max_length=256)
|
||||
avatar = models.FilePathField(max_length=512)
|
|
@ -0,0 +1,36 @@
|
|||
from unittest import TestCase
|
||||
from django.db import DatabaseError
|
||||
from regressiontests.max_lengths.models import PersonWithDefaultMaxLengths, PersonWithCustomMaxLengths
|
||||
|
||||
class MaxLengthArgumentsTests(TestCase):
|
||||
|
||||
def verify_max_length(self, model,field,length):
|
||||
self.assertEquals(model._meta.get_field(field).max_length,length)
|
||||
|
||||
def test_default_max_lengths(self):
|
||||
self.verify_max_length(PersonWithDefaultMaxLengths, 'email', 75)
|
||||
self.verify_max_length(PersonWithDefaultMaxLengths, 'vcard', 100)
|
||||
self.verify_max_length(PersonWithDefaultMaxLengths, 'homepage', 200)
|
||||
self.verify_max_length(PersonWithDefaultMaxLengths, 'avatar', 100)
|
||||
|
||||
def test_custom_maxlengths(self):
|
||||
self.verify_max_length(PersonWithCustomMaxLengths, 'email', 384)
|
||||
self.verify_max_length(PersonWithCustomMaxLengths, 'vcard', 1024)
|
||||
self.verify_max_length(PersonWithCustomMaxLengths, 'homepage', 256)
|
||||
self.verify_max_length(PersonWithCustomMaxLengths, 'avatar', 512)
|
||||
|
||||
class MaxLengthORMTests(TestCase):
|
||||
|
||||
def test_custom_max_lengths(self):
|
||||
args = {
|
||||
"email": "someone@example.com",
|
||||
"vcard": "vcard",
|
||||
"homepage": "http://example.com/",
|
||||
"avatar": "me.jpg"
|
||||
}
|
||||
|
||||
for field in ("email", "vcard", "homepage", "avatar"):
|
||||
new_args = args.copy()
|
||||
new_args[field] = "X" * 250 # a value longer than any of the default fields could hold.
|
||||
p = PersonWithCustomMaxLengths.objects.create(**new_args)
|
||||
self.assertEqual(getattr(p, field), ("X" * 250))
|
Loading…
Reference in New Issue