Ticket #10244: filefield_null.patch

File filefield_null.patch, 1.4 KB (added by siroky@…, 11 years ago)

None/NULL for FileField (v1.5.1)

  • db/models/fields/files.py

    diff --git a/db/models/fields/files.py b/db/models/fields/files.py
    index e631f17..f3bfda6 100644
    a b class FileDescriptor(object):  
    168168        # in __set__.
    169169        file = instance.__dict__[self.field.name]
    170170
     171        if file is None:
     172            return None
     173
    171174        # If this value is a string (instance.file = "path/to/file") or None
    172175        # then we simply wrap it with the appropriate attribute class according
    173176        # to the file field. [This is FieldFile for FileFields and
    class FileDescriptor(object):  
    175178        # subclasses might also want to subclass the attribute class]. This
    176179        # object understands how to convert a path to a file, and also how to
    177180        # handle None.
    178         if isinstance(file, six.string_types) or file is None:
     181        if isinstance(file, six.string_types):
    179182            attr = self.field.attr_class(instance, self.field, file)
    180183            instance.__dict__[self.field.name] = attr
    181184
    class FileField(Field):  
    238241    def get_prep_value(self, value):
    239242        "Returns field's value prepared for saving into a database."
    240243        # Need to convert File objects provided via a form to unicode for database insertion
    241         if value is None:
     244        if (value is None) or not value:
    242245            return None
    243246        return six.text_type(value)
    244247
Back to Top