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 @classmethod
def filter_for_reverse_field(cls, f, name): 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 rel = f.field.rel
default = { default = {
'name': name, 'name': name,
'label': capfirst(rel.related_name) 'label': capfirst(rel.related_name)
} }
if rel.multiple: if rel.multiple:
# For to-many relationships
return GlobalIDMultipleChoiceFilter(**default) return GlobalIDMultipleChoiceFilter(**default)
else: else:
# For to-one relationships
return GlobalIDFilter(**default) return GlobalIDFilter(**default)