From e4754649455e844c604d92883b614fe8ba81d9db Mon Sep 17 00:00:00 2001 From: Martin Hill Date: Sat, 14 Nov 2015 17:00:07 -0500 Subject: [PATCH 1/3] fix for issue #3634 --- rest_framework/utils/model_meta.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rest_framework/utils/model_meta.py b/rest_framework/utils/model_meta.py index 8eb00e4334..c1c0f61f04 100644 --- a/rest_framework/utils/model_meta.py +++ b/rest_framework/utils/model_meta.py @@ -92,7 +92,7 @@ def _get_fields(opts): def _get_to_field(field): - return field.to_fields[0] if field.to_fields else None + return field.to_fields[0] if hasattr(field, 'to_fields') else None def _get_forward_relationships(opts): From bac6f1fcf41d9c01177f5bbd031618ecd41e57f2 Mon Sep 17 00:00:00 2001 From: Martin Hill Date: Sat, 14 Nov 2015 18:26:29 -0500 Subject: [PATCH 2/3] check if field.to_fields is None --- rest_framework/utils/model_meta.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rest_framework/utils/model_meta.py b/rest_framework/utils/model_meta.py index c1c0f61f04..7a330b1eac 100644 --- a/rest_framework/utils/model_meta.py +++ b/rest_framework/utils/model_meta.py @@ -92,7 +92,7 @@ def _get_fields(opts): def _get_to_field(field): - return field.to_fields[0] if hasattr(field, 'to_fields') else None + return field.to_fields[0] if hasattr(field, 'to_fields') and field.to_fields else None def _get_forward_relationships(opts): From ff36cbe4baa50302aa566c1d188a5f98393fd895 Mon Sep 17 00:00:00 2001 From: Martin Hill Date: Sat, 14 Nov 2015 23:04:32 -0500 Subject: [PATCH 3/3] same logic, more pythonic --- rest_framework/utils/model_meta.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rest_framework/utils/model_meta.py b/rest_framework/utils/model_meta.py index 7a330b1eac..77952fbf89 100644 --- a/rest_framework/utils/model_meta.py +++ b/rest_framework/utils/model_meta.py @@ -92,7 +92,7 @@ def _get_fields(opts): def _get_to_field(field): - return field.to_fields[0] if hasattr(field, 'to_fields') and field.to_fields else None + return getattr(field, 'to_fields', None) and field.to_fields[0] def _get_forward_relationships(opts):