[PYTHON] Automatically generate model relationships with Django

Overview

A personal summary of how to automatically generate model relationships using graph_models in Django extensions. The procedure is to run inside the docker container, not env.

Preparation

Installation etc.

Install the required packages.

pip install pygraphviz
pip install pydotplus
pip install django-extensions

Note that if you try to install pygraphviz in a windows environment, you need to install the VC build tool.

Also, when doing it in a docker container, the following work was also required. Install graphviz.

apt-get install -y graphviz

If you want to output in Japanese, install Japanese fonts. Prepare the ttc file appropriately from windows etc. It's easy to put it in the Dockerfile.

$ cp meiryob.ttc /usr/share/fonts
$ fc-cache -fv

Other

If you give verbose-name to the model itself or the field in advance, you can use that name in the model diagram.

command

python3 manage.py graph_models -g -o <output name> .png --verbose-names --disable-abstract-fields <app name>

I couldn't output jpg in my environment, but can I really do it? Also, --verbose-names is an option to use verbose-name, and --disable-abstract-fields is an option to not include the inherited fields. There are many other options, such as --exclude-models to exclude unwanted models.

reference

PDF ER diagram of Models.py with Django

Recommended Posts

Automatically generate model relationships with Django
Django Model with left outer join
Automatically generate Object specifications with Blue Prism
Django model: ManyToManyField
Internationalization with django
CRUD with Django
Try to automatically generate Python documents with Sphinx
How to automatically generate API document with Django REST framework & POST from document screen
Authenticate Google with Django
Django 1.11 started with Python3.6
Upload files with Django
Development digest with Django
Output PDF with Django
Markdown output with Django
Use Gentelella with django
Getting Started with Django 1
Model fitting with lmfit
Send email with Django
Model changes in Django
High Performance Django --Model
File upload with django
I tried to automatically generate a password with Python3
Regression with linear model
Dynamically create tables in schema with Django, dynamically generate models
Use LESS with Django
Pooling mechanize with Django
Use MySQL with Django
Start today with Django
Getting Started with Django 2
[Django] Manage settings like writing in settings.py with a model
[Evangelion] Try to automatically generate Asuka-like lines with Deep Learning
Automatically generate frequency distribution table in one shot with Python
Measure and compare temperature with Raspberry Pi and automatically generate graph
Automatically download images with scraping
Do Django with CodeStar (Python3.6.8, Django2.2.9)
Get started with Django! ~ Tutorial ⑤ ~
Minimal website environment with django
Create an API with Django
Django Model Field Customization Various
Do Django with CodeStar (Python3.8, Django2.1.15)
Generate XML (RSS) with Python
Deploy Django serverless with Lambda
Python3 + Django ~ Mac ~ with Apache
Getting Started with Python Django (1)
Create a homepage with django
Getting Started with Python Django (4)
Web application creation with Django
Getting Started with Python Django (3)
Combine FastAPI with Django ORM
Get started with Django! ~ Tutorial ⑥ ~
Save tweet data with Django
Do AES encryption with DJango
Use django model from interpreter
Getting Started with Python Django (6)
Calibrate the model with PyCaret
Combine two images with Django
Getting Started with Django with PyCharm
Real-time web with Django Channels
Double submit suppression with Django
Django REST framework with Vue.js
Generate Pokemon with Deep Learning