{"id":507,"date":"2023-01-14T14:22:07","date_gmt":"2023-01-14T08:52:07","guid":{"rendered":"https:\/\/www.bhuvankrishna.in\/blog\/?p=507"},"modified":"2023-01-14T14:26:22","modified_gmt":"2023-01-14T08:56:22","slug":"generate-django-model-graphic-representation-entity-relationship-model-erd","status":"publish","type":"post","link":"https:\/\/www.bhuvankrishna.in\/blog\/2023\/01\/14\/generate-django-model-graphic-representation-entity-relationship-model-erd\/","title":{"rendered":"Generate Django Model graphic representation (Entity\u2013relationship model (ERD))"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Install <code>graphviz<\/code> and <code>libgraphviz-dev<\/code> before installing pip packages.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apt install libgraphviz-dev graphviz\npip install pygraphviz\npip install pydot\npip install django-extensions<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Add these lines to <code>settings.py<\/code> file<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>GRAPH_MODELS = {\n  'all_applications': True,\n  'group_models': True,\n}\n\nINSTALLED_APPS = (\n    ...\n    'django_extensions',\n    ...\n)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">To generate dotfiles run this command from django prompt. This is the simplest form of generating graph for all the apps.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.\/manage.py graph_models -a &gt; my_project.dot<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">To get image instead of dotfile run this command<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.\/manage.py graph_models --pygraphviz -a -g -o my_project_visualized.png<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Links for reference<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/django-extensions.readthedocs.io\/en\/latest\/graph_models.html\">https:\/\/django-extensions.readthedocs.io\/en\/latest\/graph_models.html<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/pypi.org\/project\/django-extensions\">https:\/\/pypi.org\/project\/django-extensions<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Install graphviz and libgraphviz-dev before installing pip packages. Add these lines to settings.py file To generate dotfiles run this command from django prompt. This is the simplest form of generating graph for all the apps. To get image instead of dotfile run this command Links for reference https:\/\/django-extensions.readthedocs.io\/en\/latest\/graph_models.html https:\/\/pypi.org\/project\/django-extensions<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,7,1],"tags":[],"class_list":["post-507","post","type-post","status-publish","format-standard","hentry","category-setup","category-techy","category-uncategorised"],"_links":{"self":[{"href":"https:\/\/www.bhuvankrishna.in\/blog\/wp-json\/wp\/v2\/posts\/507","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bhuvankrishna.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bhuvankrishna.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bhuvankrishna.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bhuvankrishna.in\/blog\/wp-json\/wp\/v2\/comments?post=507"}],"version-history":[{"count":2,"href":"https:\/\/www.bhuvankrishna.in\/blog\/wp-json\/wp\/v2\/posts\/507\/revisions"}],"predecessor-version":[{"id":510,"href":"https:\/\/www.bhuvankrishna.in\/blog\/wp-json\/wp\/v2\/posts\/507\/revisions\/510"}],"wp:attachment":[{"href":"https:\/\/www.bhuvankrishna.in\/blog\/wp-json\/wp\/v2\/media?parent=507"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bhuvankrishna.in\/blog\/wp-json\/wp\/v2\/categories?post=507"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bhuvankrishna.in\/blog\/wp-json\/wp\/v2\/tags?post=507"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}