Ticket #27188: 27188.diff

File 27188.diff, 3.4 KB (added by Tim Graham, 8 years ago)
  • django/db/models/fields/files.py

    diff --git a/django/db/models/fields/files.py b/django/db/models/fields/files.py
    index 0d83ef5..065b4d2 100644
    a b class FileField(Field):  
    230230
    231231    def __init__(self, verbose_name=None, name=None, upload_to='', storage=None, **kwargs):
    232232        self._primary_key_set_explicitly = 'primary_key' in kwargs
    233         self._unique_set_explicitly = 'unique' in kwargs
    234233
    235234        self.storage = storage or default_storage
    236235        self.upload_to = upload_to
    class FileField(Field):  
    240239
    241240    def check(self, **kwargs):
    242241        errors = super(FileField, self).check(**kwargs)
    243         errors.extend(self._check_unique())
    244242        errors.extend(self._check_primary_key())
    245243        return errors
    246244
    247     def _check_unique(self):
    248         if self._unique_set_explicitly:
    249             return [
    250                 checks.Error(
    251                     "'unique' is not a valid argument for a %s." % self.__class__.__name__,
    252                     obj=self,
    253                     id='fields.E200',
    254                 )
    255             ]
    256         else:
    257             return []
    258 
    259245    def _check_primary_key(self):
    260246        if self._primary_key_set_explicitly:
    261247            return [
  • docs/ref/checks.txt

    diff --git a/docs/ref/checks.txt b/docs/ref/checks.txt
    index a38cd1e..097bf3e 100644
    a b File Fields  
    183183~~~~~~~~~~~
    184184
    185185* **fields.E200**: ``unique`` is not a valid argument for a ``FileField``.
     186  *This check is removed in Django 1.11*.
    186187* **fields.E201**: ``primary_key`` is not a valid argument for a ``FileField``.
    187188* **fields.E210**: Cannot use ``ImageField`` because Pillow is not installed.
    188189
  • docs/ref/models/fields.txt

    diff --git a/docs/ref/models/fields.txt b/docs/ref/models/fields.txt
    index 873310b..96d9906 100644
    a b field, a :exc:`django.db.IntegrityError` will be raised by the model's  
    307307:meth:`~django.db.models.Model.save` method.
    308308
    309309This option is valid on all field types except :class:`ManyToManyField`,
    310 :class:`OneToOneField`, and :class:`FileField`.
     310and :class:`OneToOneField`
    311311
    312312Note that when ``unique`` is ``True``, you don't need to specify
    313313:attr:`~Field.db_index`, because ``unique`` implies the creation of an index.
    314314
     315.. versionchanged:: 1.11
     316
     317    In older versions, ``unique=True`` can't be used on :class:`FileField`.
     318
    315319``unique_for_date``
    316320-------------------
    317321
  • tests/invalid_models_tests/test_ordinary_fields.py

    diff --git a/tests/invalid_models_tests/test_ordinary_fields.py b/tests/invalid_models_tests/test_ordinary_fields.py
    index 2f16e83..aff6a74 100644
    a b class FileFieldTests(SimpleTestCase):  
    440440        expected = []
    441441        self.assertEqual(errors, expected)
    442442
    443     def test_unique(self):
    444         class Model(models.Model):
    445             field = models.FileField(unique=False, upload_to='somewhere')
    446 
    447         field = Model._meta.get_field('field')
    448         errors = field.check()
    449         expected = [
    450             Error(
    451                 "'unique' is not a valid argument for a FileField.",
    452                 obj=field,
    453                 id='fields.E200',
    454             )
    455         ]
    456         self.assertEqual(errors, expected)
    457 
    458443    def test_primary_key(self):
    459444        class Model(models.Model):
    460445            field = models.FileField(primary_key=False, upload_to='somewhere')
Back to Top