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.

You can also have a look at 
https://www.djangopackages.com/grids/g/trees-and-graphs/ 
<https://www.djangopackages.com/grids/g/trees-and-graphs/> and see if anything 
suits your needs.

Erik


> Den 02/06/2015 kl. 13.47 skrev Rafael E. Ferrero <rafael.ferr...@gmail.com 
> <mailto:rafael.ferr...@gmail.com>>:
> 
> Hello everyone,
> 
> I think to do an app where i would save a directed graph. 
> The vertex and edges there must be dinamics.  
> The vertex can represent some Tag or Category... or something. 
> The edge who links the vertex can be N between two vertex and represent some 
> event or action... and let me explain here what i need to do:
> 
> Suppose you have Vertex1 and Vertex2 and are linked by edge1 from vertex1 to 
> vertex2, edge1 have the action "Add if not exist" and mean that if the user 
> select the vertex1, the system, automatically add vertex2. Even further, 
> suppose you have a third vertex related to vertex1 by edge2 and the action of 
> that edge its "delete if exist" so if the user have, previously, selected 
> vertex3, when select vertex1, vertex3 would be deleted by edge2.
> 
> Make a model to save the graph it's not a problem (save vertex and edges and 
> specify what action have every edge)... my problem its develop every type of 
> event or action for the edges, save that event on database and then execute 
> that event when needed.
> 
> Someone have a recommendation for me?
> THANK YOU ALL!!!
> 
> --
> Rafael E. Ferrero
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users+unsubscr...@googlegroups.com 
> <mailto:django-users+unsubscr...@googlegroups.com>.
> To post to this group, send email to django-users@googlegroups.com 
> <mailto:django-users@googlegroups.com>.
> Visit this group at http://groups.google.com/group/django-users 
> <http://groups.google.com/group/django-users>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/CAJJc_8V7RiW%2Bsv4-1x9e9a7Evz4_AetSNZoyAqfoFJApwa6JJQ%40mail.gmail.com
>  
> <https://groups.google.com/d/msgid/django-users/CAJJc_8V7RiW%2Bsv4-1x9e9a7Evz4_AetSNZoyAqfoFJApwa6JJQ%40mail.gmail.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/A560D552-8EF4-4A6C-A763-E3613CC3B647%40cederstrand.dk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to