Thanks Erik, Defining custom actions its what i try to do!! because, the user can add some custom type of Action and he need to specify what to do with.
With this, the user can perform his own graph and rules to control the vertex. For example, a Contact of the business can be a Provider or a Customer for the business and, also, can be a Person or another Company but if is a Company he can't be a Person... if is a Contact, and a Provider and a Person he could be a Medic, but if is a Medic he can't be treated like a simple Provider... So, Contact, Provider, Customer, Person, Medic are the vertex and you need actions to control the automation of the graph, and the actions can be change from one implementation another. Like you say, maybe usind DSL and AST i can execute custom actions using Signal THANKS A LOT!! and now.... Do you think that this could be a good approach? or you suggest something better ?? -- Rafael E. Ferrero 2015-06-02 10:04 GMT-03:00 Erik Cederstrand <erik+li...@cederstrand.dk>: > 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/ and see if > anything suits your needs. > > Erik > > > Den 02/06/2015 kl. 13.47 skrev Rafael E. Ferrero <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. > 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/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. > > > -- > 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 > <https://groups.google.com/d/msgid/django-users/A560D552-8EF4-4A6C-A763-E3613CC3B647%40cederstrand.dk?utm_medium=email&utm_source=footer> > . > For more options, visit 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/CAJJc_8XUX3%2Bpfan1pUsg1wiB2mVBaYg8epU9_-Mu4t6HVEPf_Q%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.