diff --git a/django/db/models/base.py b/django/db/models/base.py index 6bd456763f..590aab97a4 100644 --- a/django/db/models/base.py +++ b/django/db/models/base.py @@ -459,13 +459,13 @@ class Model(object): def _get_FIELD_filename(self, field): if getattr(self, field.attname): # Value is not blank. - return os.path.normpath(os.path.join(settings.MEDIA_ROOT, field.get_filename(getattr(self, field.attname)))) + return os.path.normpath(os.path.join(settings.MEDIA_ROOT, getattr(self, field.attname))) return '' def _get_FIELD_url(self, field): if getattr(self, field.attname): # Value is not blank. import urlparse - return urlparse.urljoin(settings.MEDIA_URL, field.get_filename(getattr(self, field.attname))).replace('\\', '/') + return urlparse.urljoin(settings.MEDIA_URL, getattr(self, field.attname)).replace('\\', '/') return '' def _get_FIELD_size(self, field): diff --git a/tests/modeltests/model_forms/models.py b/tests/modeltests/model_forms/models.py index 3929774012..cc9efd0f94 100644 --- a/tests/modeltests/model_forms/models.py +++ b/tests/modeltests/model_forms/models.py @@ -12,8 +12,6 @@ import tempfile from django.db import models -TEMP_DIR = tempfile.gettempdir() - ARTICLE_STATUS = ( (1, 'Draft'), (2, 'Pending'), @@ -62,7 +60,7 @@ class PhoneNumber(models.Model): class TextFile(models.Model): description = models.CharField(max_length=20) - file = models.FileField(upload_to=TEMP_DIR) + file = models.FileField(upload_to=tempfile.gettempdir()) def __unicode__(self): return self.description @@ -73,9 +71,9 @@ class ImageFile(models.Model): # If PIL is available, try testing PIL. # Otherwise, it's equivalent to TextFile above. import Image - image = models.ImageField(upload_to=TEMP_DIR) + image = models.ImageField(upload_to=tempfile.gettempdir()) except ImportError: - image = models.FileField(upload_to=TEMP_DIR) + image = models.FileField(upload_to=tempfile.gettempdir()) def __unicode__(self): return self.description @@ -786,24 +784,6 @@ u'Assistance' # FileField ################################################################### -# File instance methods. Tests fix for #5619. - ->>> instance = TextFile(description='nothing', file='name') ->>> expected = '%s/name' % TEMP_DIR ->>> instance.get_file_filename() == expected -True ->>> instance.get_file_url() == expected -True ->>> instance.save_file_file(instance.file, SimpleUploadedFile(instance.file, 'some text')) ->>> instance.get_file_filename() == expected -True ->>> instance.get_file_url() == expected -True - ->>> os.unlink(instance.get_file_filename()) - -# File forms. - >>> class TextFileForm(ModelForm): ... class Meta: ... model = TextFile