From e5d95e319e127c1da39f7b227abd0d00654f4b72 Mon Sep 17 00:00:00 2001 From: Aider Ibragimov Date: Tue, 3 Mar 2015 16:58:04 +0300 Subject: [PATCH] fix FilePathField kwargs for django < 1.5 --- rest_framework/fields.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/rest_framework/fields.py b/rest_framework/fields.py index b6f049ea0..f2e0d9a49 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -23,6 +23,7 @@ import collections import copy import datetime import decimal +import django import inspect import re import uuid @@ -665,11 +666,18 @@ class FilePathField(CharField): def __init__(self, path, match=None, recursive=False, allow_files=True, allow_folders=False, required=None, **kwargs): super(FilePathField, self).__init__(**kwargs) + # create field and get options to avoid code duplication - field = DjangoFilePathField( - path, match=match, recursive=recursive, allow_files=allow_files, - allow_folders=allow_folders, required=required - ) + if django.VERSION < (1, 5): + # django field doesn't have allow_folders, allow_files kwargs + field = DjangoFilePathField( + path, match=match, recursive=recursive, required=required + ) + else: + field = DjangoFilePathField( + path, match=match, recursive=recursive, allow_files=allow_files, + allow_folders=allow_folders, required=required + ) self.choices = OrderedDict(field.choices) self.choice_strings_to_values = dict([