diff options
| author | Joshua Massover <joshm@simplebet.io> | 2022-01-26 15:05:33 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-02-03 09:23:02 +0100 |
| commit | c9d6e3595cfd0aa58cde1656bd735ecfcd7a872b (patch) | |
| tree | 303a984b80ffcb3c9c4dff08fb262002d64be9ac /docs/topics/http | |
| parent | e459b0f5a0b2bfbc2ac45b3e7f21047ec9e4f345 (diff) | |
Fixed #32243 -- Added docs examples for manually saving Files.
Diffstat (limited to 'docs/topics/http')
| -rw-r--r-- | docs/topics/http/file-uploads.txt | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/docs/topics/http/file-uploads.txt b/docs/topics/http/file-uploads.txt index c946662bba..a46caefed9 100644 --- a/docs/topics/http/file-uploads.txt +++ b/docs/topics/http/file-uploads.txt @@ -126,6 +126,19 @@ model:: form = UploadFileForm() return render(request, 'upload.html', {'form': form}) +If you are constructing an object manually outside of a request, you can assign +a :class:`~django.core.files.File` like object to the +:class:`~django.db.models.FileField`:: + + from django.core.management.base import BaseCommand + from django.core.files.base import ContentFile + + class MyCommand(BaseCommand): + def handle(self, *args, **options): + content_file = ContentFile(b'Hello world!', name='hello-world.txt') + instance = ModelWithFileField(file_field=content_file) + instance.save() + Uploading multiple files ------------------------ |
