summaryrefslogtreecommitdiff
path: root/django/db
diff options
context:
space:
mode:
authorPavel Shpilev <pavel.shpilev@medibank.com.au>2014-10-15 18:42:06 +1100
committerTim Graham <timograham@gmail.com>2015-01-12 09:09:18 -0500
commita7c256cb5491bf2a77abdff01638239db5bfd9d5 (patch)
tree3b3cd98b0f2f42efd989ae9dd9ab3dba473d972a /django/db
parentb5c1a85b50c709770b8e98aeecfeb8e81ca29dcf (diff)
Fixed #9893 -- Allowed using a field's max_length in the Storage.
Diffstat (limited to 'django/db')
-rw-r--r--django/db/models/fields/files.py17
1 files changed, 16 insertions, 1 deletions
diff --git a/django/db/models/fields/files.py b/django/db/models/fields/files.py
index 8ca8532113..301244bbef 100644
--- a/django/db/models/fields/files.py
+++ b/django/db/models/fields/files.py
@@ -1,5 +1,7 @@
import datetime
+from inspect import getargspec
import os
+import warnings
from django import forms
from django.db.models.fields import Field
@@ -11,6 +13,7 @@ from django.db.models import signals
from django.utils.encoding import force_str, force_text
from django.utils import six
from django.utils.translation import ugettext_lazy as _
+from django.utils.deprecation import RemovedInDjango20Warning
class FieldFile(File):
@@ -85,7 +88,19 @@ class FieldFile(File):
def save(self, name, content, save=True):
name = self.field.generate_filename(self.instance, name)
- self.name = self.storage.save(name, content)
+
+ args, varargs, varkw, defaults = getargspec(self.storage.save)
+ if 'max_length' in args:
+ self.name = self.storage.save(name, content, max_length=self.field.max_length)
+ else:
+ warnings.warn(
+ 'Backwards compatibility for storage backends without '
+ 'support for the `max_length` argument in '
+ 'Storage.save() will be removed in Django 2.0.',
+ RemovedInDjango20Warning, stacklevel=2
+ )
+ self.name = self.storage.save(name, content)
+
setattr(self.instance, self.field.name, self.name)
# Update the filesize cache