Django Cheat

Settings

postgres config

DATABASES = {    'default': {        'ENGINE': 'django.db.backends.postgresql',        'NAME': 'mydatabase',        'USER': 'mydatabaseuser',        'PASSWORD': 'mypassword',        'HOST': '127.0.0.1',        'PORT': '5432',    } }

load and pass environment varuables

set -o allexport; source .env.dev; set +o allexport; ./manage.py runserve

Migrate data from sqlite to postgres

./manage.py dumpdata --exclude auth.permission --exclude contenttypes > /tmp/dump.json ./manage.py shell

Enter the code below. It should fix incompatible content types, that are not supported by PostgreSQL.

from django.contrib.contenttypes.models import ContentType
ContentType.objects.all().delete()

Debug Test in docker

debugpy is all ready on 5678

so add 5679 to the docker container and execute the test command specifying that port:

docker compose exec facade uv run python -Xfrozen_modules=off -m debugpy --listen 0.0.0.0:5679 --wait-for-client manage.py test listings  

Configure vs code to listen on 5679:

"connect": {
    "host": "facade.local", // replace this with remote machine name
    "port": 5679
},

Docker environment:

https://testdriven.io/blog/dockerizing-django-with-postgres-gunicorn-an…

PostgreSQL

https://ioio.nu/postgresql-cheat-sheet