I know there's something similar answered here, but my question is not the same. I'm using multi-table inheritance to model 2 different types of entities, and both of them can create posts. My problem is when trying to create a view that shows all the posts together.
So I have my Entity model, and then my ETypeA and ETypeB models, which look like this:
class Entity(models.Model):
pass
class ETypeA(Entity):
# Here are some attributes
pass
class ETypeB(Entity):
# Here are some attributes
pass
As you can see, the Entity model it's just for having a common primary key between ETypeA and ETypeB. The reason for this is to have just one common Post model, like this:
class Post(models.Model):
transmitter = models.ForeignKey(Entity, on_delete=models.CASCADE)
text = models.CharField(max_length=500, null=False, blank=False)
The problem now is that when I create a view to show the posts I get only the id of the transmitter but I need the whole information. The way of doing it in SQL should be joining the results with ETypeA, then with ETypeB and make a union between the results (keeping some fields as nulls). Then I should be capable of sorting them by date. How can I do that with DRF views and serializers?