Home » Python » python – DRF: API Design-Exceptionshub

python – DRF: API Design-Exceptionshub

Posted by: admin February 24, 2020 Leave a comment

Questions:

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 like FRIEND, 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 named content_object, switching off of the content_type field.
How to&Answers: