I have a Conversation model that is made up of many Interactions. Interaction is an abstract Polymorphic model with two concrete child models Message and VoiceCall. A conversation is all the messages and calls back and forth between two people. Interaction points back to Conversation like so:
conversation = models.ForeignKey(Conversation, on_delete=models.CASCADE, related_name='%(class)ss')
This creates properties messages and voice_calls on Conversation objects that give me all associated Interactions with those subclasses, but I also want a property interactions that gives me all Interactions associated with a Conversation, and it does not appear that Polymorphic models provide this on creation.
I understand why this is impossible with vanilla Django: I've told it that Interaction is abstract, so it should never create instances of it directly, and that's exactly what the reverse_relations would try to do. However, since Polymorphic knows how to figure out the subclass of each associated Interaction, it should be possible to get all Interactions without violating the logic of abstract Models.
Is there a way to create this reverse relation on the abstract parent class?
I have a
Conversationmodel that is made up of manyInteractions.Interactionis an abstract Polymorphic model with two concrete child modelsMessageandVoiceCall. A conversation is all the messages and calls back and forth between two people.Interactionpoints back toConversationlike so:This creates properties
messagesandvoice_callsonConversationobjects that give me all associated Interactions with those subclasses, but I also want a propertyinteractionsthat gives me all Interactions associated with aConversation, and it does not appear that Polymorphic models provide this on creation.I understand why this is impossible with vanilla Django: I've told it that
Interactionis abstract, so it should never create instances of it directly, and that's exactly what the reverse_relations would try to do. However, since Polymorphic knows how to figure out the subclass of each associatedInteraction, it should be possible to get allInteractions without violating the logic of abstract Models.Is there a way to create this reverse relation on the abstract parent class?