2 ms·
No one has answered your question properly yet. This is an edge case for something called Django Content Types. It's basically a way to handle some sort of pol
by adambratt 12y ago
No one has answered your question properly yet.
This is an edge case for something called Django Content Types. It's basically a way to handle some sort of polymorphism in a table.
Let's say you have a table called activity feed like in this example. Whether the items in the feed are images, blog posts, or status updates they're all going to have something in common and you'll have endpoints that should link any relevant tables and combine them. So you'd have an activity table and it would have a column for content_type and then content_object_id. Content type is basically just a reference to another DB table (blog or status update) with more info on this activity and content_object_id is the actual id of the row in that table.
I've used Symfony, Laravel, and pretty much every other trendy PHP framework and nothing comes close to the ease of building APIs that is inherent in Django Rest Framework.
This is just a very specific use case that you normally have to handle using it's own custom class. This just shows a way you can have DRF serialize it like a normal object without issue.