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
ef082ebb
Kaydet (Commit)
ef082ebb
authored
May 02, 2019
tarafından
Mykola Kokalko
Kaydeden (comit)
Mariusz Felisiak
May 02, 2019
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #29529 -- Allowed models.fields.FilePathField to accept a callable path.
üst
11971cd8
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
30 additions
and
1 deletion
+30
-1
__init__.py
django/db/models/fields/__init__.py
+1
-1
fields.txt
docs/ref/models/fields.txt
+17
-0
3.0.txt
docs/releases/3.0.txt
+2
-0
test_filepathfield.py
tests/model_fields/test_filepathfield.py
+10
-0
No files found.
django/db/models/fields/__init__.py
Dosyayı görüntüle @
ef082ebb
...
...
@@ -1709,7 +1709,7 @@ class FilePathField(Field):
def
formfield
(
self
,
**
kwargs
):
return
super
()
.
formfield
(
**
{
'path'
:
self
.
path
,
'path'
:
self
.
path
()
if
callable
(
self
.
path
)
else
self
.
path
,
'match'
:
self
.
match
,
'recursive'
:
self
.
recursive
,
'form_class'
:
forms
.
FilePathField
,
...
...
docs/ref/models/fields.txt
Dosyayı görüntüle @
ef082ebb
...
...
@@ -868,6 +868,23 @@ directory on the filesystem. Has three special arguments, of which the first is
Required. The absolute filesystem path to a directory from which this
:class:`FilePathField` should get its choices. Example: ``"/home/images"``.
``path`` may also be a callable, such as a function to dynamically set the
path at runtime. Example::
import os
from django.conf import settings
from django.db import models
def images_path():
return os.path.join(settings.LOCAL_FILE_DIR, 'images')
class MyModel(models.Model):
file = models.FilePathField(path=images_path)
.. versionchanged:: 3.0
``path`` can now be a callable.
.. attribute:: FilePathField.match
Optional. A regular expression, as a string, that :class:`FilePathField`
...
...
docs/releases/3.0.txt
Dosyayı görüntüle @
ef082ebb
...
...
@@ -206,6 +206,8 @@ Models
* ``connection.queries`` now shows ``COPY … TO`` statements on PostgreSQL.
* :class:`~django.db.models.FilePathField` now accepts a callable ``path``.
Requests and Responses
~~~~~~~~~~~~~~~~~~~~~~
...
...
tests/model_fields/test_filepathfield.py
Dosyayı görüntüle @
ef082ebb
...
...
@@ -10,3 +10,13 @@ class FilePathFieldTests(SimpleTestCase):
field
=
FilePathField
(
path
=
path
)
self
.
assertEqual
(
field
.
path
,
path
)
self
.
assertEqual
(
field
.
formfield
()
.
path
,
path
)
def
test_callable_path
(
self
):
path
=
os
.
path
.
dirname
(
__file__
)
def
generate_path
():
return
path
field
=
FilePathField
(
path
=
generate_path
)
self
.
assertEqual
(
field
.
path
(),
path
)
self
.
assertEqual
(
field
.
formfield
()
.
path
,
path
)
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