Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
98c5370e
Kaydet (Commit)
98c5370e
authored
Mar 26, 2015
tarafından
Matt Seymour
Kaydeden (comit)
Tim Graham
Mar 26, 2015
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #24510 -- Clarified FileField.upload_to docs.
üst
4ee08958
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
11 deletions
+33
-11
fields.txt
docs/ref/models/fields.txt
+33
-11
No files found.
docs/ref/models/fields.txt
Dosyayı görüntüle @
98c5370e
...
...
@@ -598,19 +598,32 @@ Has two optional arguments:
.. attribute:: FileField.upload_to
A local filesystem path that will be appended to your :setting:`MEDIA_ROOT`
setting to determine the value of
the
:
attr:`~django.db.models.fields.files.FieldFile.url` attribute
.
This attribute provides a way of setting the upload directory and file name,
and can be set in two ways. In both cases, the value is passed to
the
:
meth:`Storage.save() <django.core.files.storage.Storage.save>` method
.
This path may contain :func:`~time.strftime` formatting, which will be
replaced by the date/time of the file upload (so that uploaded files don't
fill up the given directory).
If you specify a string value, it may contain :func:`~time.strftime`
formatting, which will be replaced by the date/time of the file upload (so
that uploaded files don't fill up the given directory). For example::
This may also be a callable, such as a function, which will be called to
obtain the upload path, including the filename. This callable must be able
to accept two arguments, and return a Unix-style path (with forward slashes)
to be passed along to the storage system. The two arguments that will be
passed are:
class MyModel(models.Model):
# file will be uploaded to MEDIA_ROOT/uploads
upload = models.FileField(upload_to='uploads/')
# or...
# file will be saved to MEDIA_ROOT/uploads/2015/01/30
upload = models.FileField(upload_to='uploads/%Y/%m/%d/')
If you are using the default
:class:`~django.core.files.storage.FileSystemStorage`, the string value
will be appended to your :setting:`MEDIA_ROOT` path to form the location on
the local filesystem where uploaded files will be stored. If you are using
a different storage, check that storage's documentation to see how it
handles ``upload_to``.
``upload_to`` may also be a callable, such as a function. This will be
called to obtain the upload path, including the filename. This callable must
accept two arguments and return a Unix-style path (with forward slashes)
to be passed along to the storage system. The two arguments are:
====================== ===============================================
Argument Description
...
...
@@ -630,6 +643,15 @@ Has two optional arguments:
when determining the final destination path.
====================== ===============================================
For example::
def user_directory_path(instance, filename):
# file will be uploaded to MEDIA_ROOT/user_<id>/<filename>
return 'user_{0}/{1}'.format(instance.user.id, filename)
class MyModel(models.Model):
upload = models.FileField(upload_to=user_directory_path)
.. attribute:: FileField.storage
A storage object, which handles the storage and retrieval of your
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment