I’m using the ContentType framework and GenericForeignKeys with Django. When embedding the content_object
into an object field for serialization– is it better to embed it as a field named content_object
? Or as a named field that’s injected?
So for example, let’s say I have notifications with a loosely associated object:
Should I:
- Inject a
type
field for the client to consume, with types likeFRIEND
,ALERT
and so on. - Inject a relevant object, like
friend
,alert
OR
- Infer the type from the content_type field. However this will be unreadable, so the client will simply need to know this enum.
- Injet the relevant
content_object
field but keep it namedcontent_object
, switching off of thecontent_type
field.
Tags: api, design, exception, pythonpython