Nathan Harmston
unread,Jan 13, 2007, 12:20:25 PM1/13/07Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to django...@googlegroups.com
Hi,
I ve decided to try to use django in a project of mine to display some
results. I have an idea of how I m going to implement the database but
not how this translate to a django data model. I am trying to use a
database to store a graph of Nodes to Nodes with Edges. However there
are multiple edge types and multiple node types, I m trying to make
this as generic as possible.
e.g Node1_(n typeA) --Edge1_(e typeA) ---> Node2_(n typeA)
Node1_(n typeA) --Edge1_(e typeA) ---> Node3_(n typeB)
Node1_(n typeA) --Edge1_(e typeB) ---> Node2_(n typeA)
# if u get me??
So my idea was to implement to build a database like this:
Node Types Table:
primary_key, type
# where type relates to the name of a table holding node types, this is duplicated for edges
Relationships Table:
primary_key,
source_node_type, source_node_id, dest_node_type, dest_node_id,
edge_type, edge_id
But the problem is I cant implement this in Django, is there a simple
way of doing this, the code below is as far as I got in defining a
model however I got stuck when implementing the Relationship table.
class Interval(models.Model): # a node
start = models.IntegerField()
end = models.IntegerField()
class Feature(models.Model): # a node
name = models.TextField()
class SSaha(models.Model): # an edge
score = models.IntegerField()
class Blast(models.Model): # an edge
score = models.IntegerField()
class Node_Type(models.Model): # will contain (0, Interval) (1, Feature)
type = models.TextField()
class Edge_Type(models.Model): # will contain (0, SSaha) (1, Blast)
type = models.TextField()
class Relationship(models.Model):
src_type = models.ForeignKey(Node_Type)
src = models.ForeignKey()
dest_type = models.ForeignKey(Node_Type)
dest = models.FoeignKey()
edge_type = models.ForeignKey(Edge_Type)
edge = models.ForeignKey()
I m sorry if this isnt the best explanation. Any help would be gratefully appreciated.
Many Thanks
Nathan