Commit c0c08869 authored by Florent Chehab's avatar Florent Chehab

Add a bypass option in the dictmodeview

parent 0d2b5992
......@@ -6,12 +6,14 @@ class DictModeViewSet(viewsets.ModelViewSet):
ViewSet that renders data as dict with keys corresponding to the model
primary key. Instead of list.
"""
BYPASS_DICT_MODE = False
def list(self, request, *args, **kwargs):
response = super(viewsets.ModelViewSet, self).list( # pylint: disable=E1003
request, *args, **kwargs) # call the original 'list'
pk_attr_name = self.serializer_class.Meta.model._meta.pk.name
response.data = {
d[pk_attr_name]: d for d in response.data
}
if not self.BYPASS_DICT_MODE:
pk_attr_name = self.serializer_class.Meta.model._meta.pk.name
response.data = {
d[pk_attr_name]: d for d in response.data
}
return response
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment