diff --git a/dynamic_rest/filters.py b/dynamic_rest/filters.py index 495c6d62..e27b0d6a 100644 --- a/dynamic_rest/filters.py +++ b/dynamic_rest/filters.py @@ -114,9 +114,10 @@ def generate_query_key(self, serializer): # For remote fields, strip off '_set' for filtering. This is a # weird Django inconsistency. model_field_name = field.source or field_name - model_field = get_model_field(s.get_model(), model_field_name) - if isinstance(model_field, RelatedObject): - model_field_name = model_field.field.related_query_name() + if is_model_field(s.get_model(), model_field_name): + model_field = get_model_field(s.get_model(), model_field_name) + if isinstance(model_field, RelatedObject): + model_field_name = model_field.field.related_query_name() # If get_all_fields() was used above, field could be unbound, # and field.source would be None