Hi Rafael,
Assuming you have a static and limited set of actions, and they can only be defined programmatically, I would do something like this:
class Vertex(models.Model):
some_field = models.CharField()
class Edge(models.Model):
from = models.ForeignKey(Vertex, related_name='outgoing')
to = models.ForeignKey(Vertex, related_name='incoming')
action = models.CharField(choices=(('action1', 'action1'), ('action2', 'action2'), ...))
def action1(self):
# Do something here
pass
def action2(self):
# Do something else here
pass
def run_action(self):
return getattr(self, self.action)()
When and where to call run_action() would depend on your requirements - either in the save() method on Edge, in a signal, or within a view.
If you were looking to define custom actions on the fly via a GUI, you would need to define a DSL containing the constructs you allow, create a view where the user can compose an AST using the constructs of the DSL, and store the resulting AST in the database. When you need to run the action, you would translate the AST to Python and run that.
Erik