Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: EA_enthusiast on January 10, 2021, 12:54:11 pm
-
Hello, EA Experts,
I imported this Python code
https://ibb.co/RQrJRLb
To get these classes on a diagram but without relationships shown
https://ibb.co/C9H2LHX
When I transformed the model to DDL, I still do not see relationships
https://ibb.co/mBv3zgt
I checked the diagram properties and I confirmed that "Show Relationships" is checked
https://ibb.co/M14VSnL
What should I do to show the relationships?
Thank you,
Mo
-
I guess EA didn't create any relationships when importing your code.
Geert
-
class without self? What Python code is that?
q.
-
Thank you, Geert and q. for your responses.
Is this a problem from EA's side or something missing in the code?
Is there a way to fix that?
Thank you,
Mo
-
The problem is that Python doesn't explicitly declare the type for the variables and EA can't infer it.
-
Well, your code isn't Python. A class needs self as first parameter. Always. Formally: this is not a sentence of the Python language. The compiler will not swallow it. And EA will probably not even croak but do "something".
q.
-
Are you sure qwerty?
My (limited) Python understanding says that what is defined there are class definitions with static variables. As there are no methods at all there's no reason why there should be a self parameter. I assume that django requires a database structure to to be specified like this.
-
I have very little knowledge of Python. I just got this code from another team member and tried to import it to EA.
It was successfully imported (as a Python code) but with no relationships on the class diagram created by EA as I indicated earlier
When I told the developer that there are no relationships shown in EA, he exported this ERD from Django-extensions (and it shows relationships)
https://ibb.co/NSV9zYc
He also shared the below code of the ERD (as a .dott file) but I could not import this .dot file to EA
digraph model_graph {
// Dotfile by Django-Extensions graph_models
// Created: 2021-01-08 07:36
// Cli Options: -a
fontname = "Roboto"
fontsize = 8
splines = true
node [
fontname = "Roboto"
fontsize = 8
shape = "plaintext"
]
edge [
fontname = "Roboto"
fontsize = 8
]
// Labels
django_contrib_admin_models_LogEntry [label=<
<TABLE BGCOLOR="white" BORDER="1" CELLBORDER="0" CELLSPACING="0">
<TR><TD COLSPAN="2" CELLPADDING="5" ALIGN="CENTER" BGCOLOR="#1b563f">
<FONT FACE="Roboto" COLOR="white" POINT-SIZE="10"><B>
LogEntry
</B></FONT></TD></TR>
<TR><TD ALIGN="LEFT" BORDER="0">
<FONT FACE="Roboto"><B>id</B></FONT>
</TD><TD ALIGN="LEFT">
<FONT FACE="Roboto"><B>AutoField</B></FONT>
</TD></TR>
<TR><TD ALIGN="LEFT" BORDER="0">
<FONT COLOR="#7B7B7B" FACE="Roboto"><B>content_type</B></FONT>
</TD><TD ALIGN="LEFT">
<FONT COLOR="#7B7B7B" FACE="Roboto"><B>ForeignKey (id)</B></FONT>
</TD></TR>
<TR><TD ALIGN="LEFT" BORDER="0">
<FONT FACE="Roboto"><B>user</B></FONT>
</TD><TD ALIGN="LEFT">
<FONT FACE="Roboto"><B>ForeignKey (id)</B></FONT>
</TD></TR>
<TR><TD ALIGN="LEFT" BORDER="0">
<FONT FACE="Roboto">action_flag</FONT>
</TD><TD ALIGN="LEFT">
<FONT FACE="Roboto">PositiveSmallIntegerField</FONT>
</TD></TR>
<TR><TD ALIGN="LEFT" BORDER="0">
<FONT FACE="Roboto">action_time</FONT>
</TD><TD ALIGN="LEFT">
<FONT FACE="Roboto">DateTimeField</FONT>
</TD></TR>
<TR><TD ALIGN="LEFT" BORDER="0">
<FONT COLOR="#7B7B7B" FACE="Roboto">change_message</FONT>
</TD><TD ALIGN="LEFT">
<FONT COLOR="#7B7B7B" FACE="Roboto">TextField</FONT>
</TD></TR>
<TR><TD ALIGN="LEFT" BORDER="0">
<FONT COLOR="#7B7B7B" FACE="Roboto">object_id</FONT>
</TD><TD ALIGN="LEFT">
<FONT COLOR="#7B7B7B" FACE="Roboto">TextField</FONT>
</TD></TR>
<TR><TD ALIGN="LEFT" BORDER="0">
<FONT FACE="Roboto">object_repr</FONT>
</TD><TD ALIGN="LEFT">
<FONT FACE="Roboto">CharField</FONT>
</TD></TR>
</TABLE>
>]
django_contrib_auth_models_AbstractUser [label=<
<TABLE BGCOLOR="white" BORDER="1" CELLBORDER="0" CELLSPACING="0">
<TR><TD COLSPAN="2" CELLPADDING="5" ALIGN="CENTER" BGCOLOR="#1b563f">
<FONT FACE="Roboto" COLOR="white" POINT-SIZE="10"><B>
AbstractUser<BR/><<FONT FACE="Roboto"><I>AbstractBaseUser,PermissionsMixin</I></FONT>>
</B></FONT></TD></TR>
<TR><TD ALIGN="LEFT" BORDER="0">
<FONT FACE="Roboto">date_joined</FONT>
</TD><TD ALIGN="LEFT">
<FONT FACE="Roboto">DateTimeField</FONT>
</TD></TR>
<TR><TD ALIGN="LEFT" BORDER="0">
<FONT COLOR="#7B7B7B" FACE="Roboto">email</FONT>
</TD><TD ALIGN="LEFT">
<FONT COLOR="#7B7B7B" FACE="Roboto">EmailField</FONT>
</TD></TR>
<TR><TD ALIGN="LEFT" BORDER="0">
<FONT COLOR="#7B7B7B" FACE="Roboto">first_name</FONT>
</TD><TD ALIGN="LEFT">
<FONT COLOR="#7B7B7B" FACE="Roboto">CharField</FONT>
</TD></TR>
<TR><TD ALIGN="LEFT" BORDER="0">
<FONT FACE="Roboto">is_active</FONT>
</TD><TD ALIGN="LEFT">
<FONT FACE="Roboto">BooleanField</FONT>
</TD></TR>
<TR><TD ALIGN="LEFT" BORDER="0">
<FONT FACE="Roboto">is_staff</FONT>
</TD><TD ALIGN="LEFT">
<FONT FACE="Roboto">BooleanField</FONT>
</TD></TR>
<TR><TD ALIGN="LEFT" BORDER="0">
<FONT FACE="Roboto"><I>is_superuser</I></FONT>
</TD><TD ALIGN="LEFT">
<FONT FACE="Roboto"><I>BooleanField</I></FONT>
</TD></TR>
<TR><TD ALIGN="LEFT" BORDER="0">
<FONT COLOR="#7B7B7B" FACE="Roboto"><I>last_login</I></FONT>
</TD><TD ALIGN="LEFT">
<FONT COLOR="#7B7B7B" FACE="Roboto"><I>DateTimeField</I></FONT>
</TD></TR>
<TR><TD ALIGN="LEFT" BORDER="0">
<FONT COLOR="#7B7B7B" FACE="Roboto">last_name</FONT>
</TD><TD ALIGN="LEFT">
<FONT COLOR="#7B7B7B" FACE="Roboto">CharField</FONT>
</TD></TR>
<TR><TD ALIGN="LEFT" BORDER="0">
<FONT FACE="Roboto"><I>password</I></FONT>
</TD><TD ALIGN="LEFT">
<FONT FACE="Roboto"><I>CharField</I></FONT>
</TD></TR>
<TR><TD ALIGN="LEFT" BORDER="0">
<FONT FACE="Roboto">username</FONT>
</TD><TD ALIGN="LEFT">
<FONT FACE="Roboto">CharField</FONT>
</TD></TR>
</TABLE>
>]
django_contrib_auth_models_Permission [label=<
<TABLE BGCOLOR="white" BORDER="1" CELLBORDER="0" CELLSPACING="0">
<TR><TD COLSPAN="2" CELLPADDING="5" ALIGN="CENTER" BGCOLOR="#1b563f">
<FONT FACE="Roboto" COLOR="white" POINT-SIZE="10"><B>
Permission
</B></FONT></TD></TR>
<TR><TD ALIGN="LEFT" BORDER="0">
<FONT FACE="Roboto"><B>id</B></FONT>
</TD><TD ALIGN="LEFT">
<FONT FACE="Roboto"><B>AutoField</B></FONT>
</TD></TR>
<TR><TD ALIGN="LEFT" BORDER="0">
<FONT FACE="Roboto"><B>content_type</B></FONT>
</TD><TD ALIGN="LEFT">
<FONT FACE="Roboto"><B>ForeignKey (id)</B></FONT>
</TD></TR>
<TR><TD ALIGN="LEFT" BORDER="0">
<FONT FACE="Roboto">codename</FONT>
</TD><TD ALIGN="LEFT">
<FONT FACE="Roboto">CharField</FONT>
</TD></TR>
<TR><TD ALIGN="LEFT" BORDER="0">
<FONT FACE="Roboto">name</FONT>
</TD><TD ALIGN="LEFT">
<FONT FACE="Roboto">CharField</FONT>
</TD></TR>
</TABLE>
>]
django_contrib_auth_models_Group [label=<
<TABLE BGCOLOR="white" BORDER="1" CELLBORDER="0" CELLSPACING="0">
<TR><TD COLSPAN="2" CELLPADDING="5" ALIGN="CENTER" BGCOLOR="#1b563f">
<FONT FACE="Roboto" COLOR="white" POINT-SIZE="10"><B>
Group
</B></FONT></TD></TR>
<TR><TD ALIGN="LEFT" BORDER="0">
<FONT FACE="Roboto"><B>id</B></FONT>
</TD><TD ALIGN="LEFT">
<FONT FACE="Roboto"><B>AutoField</B></FONT>
</TD></TR>
<TR><TD ALIGN="LEFT" BORDER="0">
<FONT FACE="Roboto">name</FONT>
</TD><TD ALIGN="LEFT">
<FONT FACE="Roboto">CharField</FONT>
</TD></TR>
</TABLE>
>]
django_contrib_auth_models_User [label=<
<TABLE BGCOLOR="white" BORDER="1" CELLBORDER="0" CELLSPACING="0">
<TR><TD COLSPAN="2" CELLPADDING="5" ALIGN="CENTER" BGCOLOR="#1b563f">
<FONT FACE="Roboto" COLOR="white" POINT-SIZE="10"><B>
User<BR/><<FONT FACE="Roboto"><I>AbstractUser</I></FONT>>
</B></FONT></TD></TR>
<TR><TD ALIGN="LEFT" BORDER="0">
<FONT FACE="Roboto"><B>id</B></FONT>
</TD><TD ALIGN="LEFT">
<FONT FACE="Roboto"><B>AutoField</B></FONT>
</TD></TR>
<TR><TD ALIGN="LEFT" BORDER="0">
<FONT FACE="Roboto"><I>date_joined</I></FONT>
</TD><TD ALIGN="LEFT">
<FONT FACE="Roboto"><I>DateTimeField</I></FONT>
</TD></TR>
<TR><TD ALIGN="LEFT" BORDER="0">
<FONT COLOR="#7B7B7B" FACE="Roboto"><I>email</I></FONT>
</TD><TD ALIGN="LEFT">
<FONT COLOR="#7B7B7B" FACE="Roboto"><I>EmailField</I></FONT>
</TD></TR>
<TR><TD ALIGN="LEFT" BORDER="0">
<FONT COLOR="#7B7B7B" FACE="Roboto"><I>first_name</I></FONT>
</TD><TD ALIGN="LEFT">
<FONT COLOR="#7B7B7B" FACE="Roboto"><I>CharField</I></FONT>
</TD></TR>
<TR><TD ALIGN="LEFT" BORDER="0">
<FONT FACE="Roboto"><I>is_active</I></FONT>
</TD><TD ALIGN="LEFT">
<FONT FACE="Roboto"><I>BooleanField</I></FONT>
</TD></TR>
<TR><TD ALIGN="LEFT" BORDER="0">
<FONT FACE="Roboto"><I>is_staff</I></FONT>
</TD><TD ALIGN="LEFT">
<FONT FACE="Roboto"><I>BooleanField</I></FONT>
</TD></TR>
<TR><TD ALIGN="LEFT" BORDER="0">
<FONT FACE="Roboto"><I>is_superuser</I></FONT>
</TD><TD ALIGN="LEFT">
<FONT FACE="Roboto"><I>BooleanField</I></FONT>
</TD><...
-
What did you expect? I didn't see any relations in the python code, just a whole bunch of html inside the code.
If EA parses code it will show the relations it can extract from the code. It will definitely not parse the HTML and do something with it.
Geert
-
Thank you, Geert.
But do you know how did he manage to export an ERD (with relationships ) from Django-extensions? Also, the image he extracted from Django shows relationships.
When I noticed no relations in the Python code and asked the developed, he said "look for models.forignkey"
Any advice would be appreciated.
Thank you,
Mo
-
Are you sure qwerty?
My (limited) Python understanding says that what is defined there are class definitions with static variables. As there are no methods at all there's no reason why there should be a self parameter. I assume that django requires a database structure to to be specified like this.
Well, it was late. They use the Django framework. So this IS legal Python. However, I don't think Sparx is using a fullly fledged Python compiler and will not recognize that structure. Personally I would not blame EA for not being able...
q.
-
When I noticed no relations in the Python code and asked the developed, he said "look for models.forignkey"
EA imports associations between classes when the explicitly declared type matches the name of another class.
It can not infer the type from the ways that it is used, including the initial value. Even if it could, it knows nothing about django in order to parse the model.ForeignKey invocation.
-
Thank you, Eve, q. and Geert for your input. I really appreciate it.