Adding comments to filter_for_reverse_field()

This commit is contained in:
Adam Charnock 2015-12-04 01:57:43 +00:00
parent 64ec0ca94f
commit be6b2bf290

View File

@ -58,14 +58,22 @@ class GrapheneFilterSetMixin(object):
@classmethod
def filter_for_reverse_field(cls, f, name):
"""Handles retrieving filters for reverse relationships
We override the default implementation so that we can handle
Global IDs (the default implementation expects database
primary keys)
"""
rel = f.field.rel
default = {
'name': name,
'label': capfirst(rel.related_name)
}
if rel.multiple:
# For to-many relationships
return GlobalIDMultipleChoiceFilter(**default)
else:
# For to-one relationships
return GlobalIDFilter(**default)