mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-23 01:57:00 +03:00
Merge pull request #3536 from jpadilla/filepathfield-mapping
Map all supported FilePathField options
This commit is contained in:
commit
9a78db2707
|
@ -106,6 +106,21 @@ def get_field_kwargs(field_name, model_field):
|
|||
isinstance(model_field, models.TextField)):
|
||||
kwargs['allow_blank'] = True
|
||||
|
||||
if isinstance(model_field, models.FilePathField):
|
||||
kwargs['path'] = model_field.path
|
||||
|
||||
if model_field.match is not None:
|
||||
kwargs['match'] = model_field.match
|
||||
|
||||
if model_field.recursive is not False:
|
||||
kwargs['recursive'] = model_field.recursive
|
||||
|
||||
if model_field.allow_files is not True:
|
||||
kwargs['allow_files'] = model_field.allow_files
|
||||
|
||||
if model_field.allow_folders is not False:
|
||||
kwargs['allow_folders'] = model_field.allow_folders
|
||||
|
||||
if model_field.choices:
|
||||
# If this model field contains choices, then return early.
|
||||
# Further keyword arguments are not valid.
|
||||
|
|
|
@ -67,6 +67,7 @@ class RegularFieldsModel(models.Model):
|
|||
time_field = models.TimeField()
|
||||
url_field = models.URLField(max_length=100)
|
||||
custom_field = CustomField()
|
||||
file_path_field = models.FilePathField(path='/tmp/')
|
||||
|
||||
def method(self):
|
||||
return 'method'
|
||||
|
@ -165,6 +166,7 @@ class TestRegularFieldMappings(TestCase):
|
|||
time_field = TimeField()
|
||||
url_field = URLField(max_length=100)
|
||||
custom_field = ModelField(model_field=<tests.test_model_serializer.CustomField: custom_field>)
|
||||
file_path_field = FilePathField(path='/tmp/')
|
||||
""")
|
||||
|
||||
self.assertEqual(unicode_repr(TestSerializer()), expected)
|
||||
|
|
Loading…
Reference in New Issue
Block a user