Ticket #10244: nullable_file_field.diff

File nullable_file_field.diff, 1.1 KB (added by Ondrej Pudiš, 20 months ago)
  • django/db/models/fields/files.py

    diff --git a/django/db/models/fields/files.py b/django/db/models/fields/files.py
    index 3d1291a..edc5566 100644
    a b class FileDescriptor(DeferredAttribute):  
    180180        # in __set__.
    181181        file = super().__get__(instance, cls)
    182182
    183         # If this value is a string (instance.file = "path/to/file") or None
     183        # If this value is a string (instance.file = "path/to/file")
    184184        # then we simply wrap it with the appropriate attribute class according
    185185        # to the file field. [This is FieldFile for FileFields and
    186186        # ImageFieldFile for ImageFields; it's also conceivable that user
    187187        # subclasses might also want to subclass the attribute class]. This
    188188        # object understands how to convert a path to a file, and also how to
    189189        # handle None.
    190         if isinstance(file, str) or file is None:
     190        if isinstance(file, str):
    191191            attr = self.field.attr_class(instance, self.field, file)
    192192            instance.__dict__[self.field.attname] = attr
    193193
Back to Top