I'm finding some difficulty resolving this problem in designing my Django models.
The essential setup is a bipartite graph allowing for parallel edges. Trying our hardest to keep vertices in a single class, what is the most succinct means we have for querying all the edges incident to a vertex?
The instruction to keep vertices encoded by a single class comes from a (possibly misguided) urgency I have to consolidate vertices within a signle database.
I considered using an inheritance scheme, wherein vertices in a partition inherit from a polymorphic parent Vertex
class, but I kept tripping up, and really started worrying about whether Django had some (unkown to me) native and concise means of doing this.
The current setup is about:
class Vertex(models.Model):
PARTITION_CHOICES = (
('a': 'type a'),
('b': 'type b')
)
partition = models.CharField(choices=PARTITION_CHOICES)
# A bunch of other attributes...
class Edge(models.Model):
vertex_a = models.ForeignKey(Vertex, limit_choices_to={'partition': 'a'}, related_name='edges')
vertex_b = models.ForeignKey(Vertex, limit_choices_to={'partition': 'b'}, related_name='edges')
# More attributes...
The obvious issue here is that both these foreign keys have the same related name, therefore clash. Otherwise, I would be able to quite neatly ask for vertex.edges.all()
.
Tips from the wise?