diff options
author | Jacob Kaplan-Moss <jacob@jacobian.org> | 2009-01-16 21:48:37 +0000 |
---|---|---|
committer | Jacob Kaplan-Moss <jacob@jacobian.org> | 2009-01-16 21:48:37 +0000 |
commit | 6332ad4804a040ec6a4869e69d484c7336a5cad1 (patch) | |
tree | a8ad9dd5970c01659000b028623a5f6b2a05dac0 /tests/modeltests | |
parent | 79138a61065bf0c789d9f3f34c55de2e26fda422 (diff) | |
download | django-6332ad4804a040ec6a4869e69d484c7336a5cad1.tar.gz |
Fixed #10044: You can now assign directly to file fields (`instance.filefield = somefile`). Thanks, Marty Alchin.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@9766 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/modeltests')
-rw-r--r-- | tests/modeltests/files/models.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/modeltests/files/models.py b/tests/modeltests/files/models.py index 3df3122cdb..741a28411b 100644 --- a/tests/modeltests/files/models.py +++ b/tests/modeltests/files/models.py @@ -9,6 +9,7 @@ import shutil import tempfile from django.db import models from django.core.files.base import ContentFile +from django.core.files.uploadedfile import SimpleUploadedFile from django.core.files.storage import FileSystemStorage from django.core.cache import cache @@ -54,6 +55,23 @@ ValueError: The 'normal' attribute has no file associated with it. >>> obj1.normal.read() 'content' +# File objects can be assigned to FileField attributes, but shouldn't get +# committed until the model it's attached to is saved. + +>>> obj1.normal = SimpleUploadedFile('assignment.txt', 'content') +>>> dirs, files = temp_storage.listdir('tests') +>>> dirs +[] +>>> files.sort() +>>> files +[u'default.txt', u'django_test.txt'] + +>>> obj1.save() +>>> dirs, files = temp_storage.listdir('tests') +>>> files.sort() +>>> files +[u'assignment.txt', u'default.txt', u'django_test.txt'] + # Files can be read in a little at a time, if necessary. >>> obj1.normal.open() |