I'm using graphviz with my Django models to render graphs from the following python script for each automata:
alphabets = automata.alphabet_set.all()
states = automata.states_set.all()
transitions = automata.transition_set.all()
dot = gv.Graph()
for state in states:
dot.node(state.state, state.state)
for transition in transitions:
dot.edge(transition.current_state, transition.next_state, transition.input)
dot.render( automata.id + '.gv', view=True)
And these are my models:
class Automata(models.Model):
pass
class Alphabet(models.Model):
alphabet = models.CharField()
automata = models.ForeignKey(Automata, on_delete = models.CASCADE)
class States(models.Model):
state = models.CharField()
automata = models.ForeignKey(Automata, on_delete = models.CASCADE)
class Transition(models.Model):
current_state = models.ForeignKey(States, on_delete = models.CASCADE, related_name = 'current')
input = models.ForeignKey(Alphabet, on_delete = models.CASCADE)
next_state = models.ForeignKey(States, on_delete = models.CASCADE, related_name = 'next')
automata = models.ForeignKey(Automata, on_delete = models.CASCADE)
but everytime I try to execute my script I get the following error:
Traceback (most recent call last):
File "make_graph.py", line 36, in <module>
dot.edge(transition.current_state, transition.next_state, transition.input)
File "/home/nids/automata/auto/lib/python3.5/site-packages/graphviz/dot.py", line 116, in edge
tail_name = self.quote_edge(tail_name)
File "/home/nids/automata/auto/lib/python3.5/site-packages/graphviz/lang.py", line 63, in quote_edge
node, _, rest = identifier.partition(':')
AttributeError: 'States' object has no attribute 'partition'
Knowing that I have no error if I simply do: dot.edge('A', 'B', 'edge label')
The graphvis code is expecting a string to be passed into it, not a States object (your model).
You can see this in the source code in the quote_edge function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With