Skip to content

Commit d014754

Browse files
authored
Make PrimaryKeyWriteSerializerReadField work with Browsable API
1 parent f038050 commit d014754

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

ckc/fields.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,9 @@ def use_pk_only_optimization(self):
1616
return False
1717

1818
def to_representation(self, value):
19-
return self.read_serializer(value, context=self.context).data
19+
# Are we on the browsable API? if so, just return pk!
20+
if self.context['request'].META["HTTP_ACCEPT"].startswith("text/html"):
21+
return value.pk
22+
else:
23+
# Normal request, return full item read details
24+
return self.read_serializer(value, context=self.context).data

0 commit comments

Comments
 (0)