I stumbled upon outputting a table configuration diagram with the Django app, so I wrote it as a memorandum. I have cloned Doccano as an annotation tool in my work, but I want to check how the table structure is. had. The development environment of Doccano is created by Docker.
I used django-extension's graph_models to output the ER diagram.
Doccano's docker-compose.yml is divided into development and production.
python:docker-compose.dev.yml
version: "3.7"
services:
backend:
image: python:3.6
volumes:
- .:/src
- venv:/src/venv
command: ["/src/app/tools/dev-django.sh", "0.0.0.0:8000"]
environment:
ADMIN_USERNAME: "admin"
ADMIN_PASSWORD: "password"
ADMIN_EMAIL: "[email protected]"
DATABASE_URL: "postgres://doccano:doccano@postgres:5432/doccano?sslmode=disable"
ALLOW_SIGNUP: "False"
DEBUG: "True"
ports:
- 8000:8000
depends_on:
- postgres
networks:
- network-backend
- network-frontend
frontend:
image: node:13.7.0
command: ["/src/frontend/dev-nuxt.sh"]
volumes:
- .:/src
- node_modules:/src/frontend/node_modules
ports:
- 3000:3000
depends_on:
- backend
networks:
- network-frontend
postgres:
image: postgres:12.0-alpine
volumes:
- postgres_data:/var/lib/postgresql/data/
environment:
POSTGRES_USER: "doccano"
POSTGRES_PASSWORD: "doccano"
POSTGRES_DB: "doccano"
networks:
- network-backend
volumes:
postgres_data:
node_modules:
venv:
networks:
network-backend:
network-frontend:
Install the library from here. Add the following three lines to src / requirements.txt.
requirements.txt
graphviz
pydotplus
django-extensions
I will start up the container.
docker-compose -f docker-compose.dev.yml up #Container launch
docker ps #Check the container name
docker exec -it doccano_backend_1 bash #Enter bash
Next, we will work in the bash of the container.
cd src #Move to src
pip install -r requirements.txt #Library installation
apt install graphviz #installation of graphviz
Then add django_extensions
to INSTALLED_APPS in app / settings.py.
setting.py
INSTALLED_APPS = [
'whitenoise.runserver_nostatic',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'server.apps.ServerConfig',
'api.apps.ApiConfig',
'widget_tweaks',
'rest_framework',
'rest_framework.authtoken',
'django_filters',
'social_django',
'polymorphic',
'webpack_loader',
'corsheaders',
'drf_yasg',
'django_extensions'β Add
]
Drop the container once with docker-compose down
and start it again.
docker-compose -f docker-compose.dev.yml up --force-recreate
Enter the bash of the container again and output the ER diagram.
docker exec -it doccano_backend_1 bash
cd src #Move to src
source venv/bin/activate #Enter the virtual environment
cd src/app #manage.Move to the directory where py is
python3 manage.py graph_models -a -g -o graph-model.pdf #Output ER diagram
In Doccano, the container under src is mounted in the host directory, so you can open the pdf from the host side as it is.
-PDF ER diagram of Models.py with Django -GraphViz βs executables not found
Recommended Posts