Skip to content

Commit 9a78db2

Browse files
committed
Merge pull request #3536 from jpadilla/filepathfield-mapping
Map all supported FilePathField options
2 parents c53c9ed + d64bfef commit 9a78db2

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

rest_framework/utils/field_mapping.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,21 @@ def get_field_kwargs(field_name, model_field):
106106
isinstance(model_field, models.TextField)):
107107
kwargs['allow_blank'] = True
108108

109+
if isinstance(model_field, models.FilePathField):
110+
kwargs['path'] = model_field.path
111+
112+
if model_field.match is not None:
113+
kwargs['match'] = model_field.match
114+
115+
if model_field.recursive is not False:
116+
kwargs['recursive'] = model_field.recursive
117+
118+
if model_field.allow_files is not True:
119+
kwargs['allow_files'] = model_field.allow_files
120+
121+
if model_field.allow_folders is not False:
122+
kwargs['allow_folders'] = model_field.allow_folders
123+
109124
if model_field.choices:
110125
# If this model field contains choices, then return early.
111126
# Further keyword arguments are not valid.

tests/test_model_serializer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class RegularFieldsModel(models.Model):
6767
time_field = models.TimeField()
6868
url_field = models.URLField(max_length=100)
6969
custom_field = CustomField()
70+
file_path_field = models.FilePathField(path='/tmp/')
7071

7172
def method(self):
7273
return 'method'
@@ -165,6 +166,7 @@ class Meta:
165166
time_field = TimeField()
166167
url_field = URLField(max_length=100)
167168
custom_field = ModelField(model_field=<tests.test_model_serializer.CustomField: custom_field>)
169+
file_path_field = FilePathField(path='/tmp/')
168170
""")
169171

170172
self.assertEqual(unicode_repr(TestSerializer()), expected)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy