Django - Notes & Useful commands

Here you can find useful Django commands:

Django basics

python runserver --insecure
python shell
python makemigrations laws
python migrate
python createsuperuser
./ changepassword admin  #to set the password for the Django admin user

python startapp appname
python test appname

Custom commands

python process_laws --empty --limit 100 --min-lines 1000
python process_cases --limit 10
python import_courts --input oldp/apps/courts/data/ecli.csv --empty

In dev & before deployment

python collectstatic --noinput
python collectstatic --noinput --ignore=*.scss

./ compilescss

python makemessages --locale=en --locale=de --ignore=env --ignore=workingdir
python compilemessages --l de --l en

# API token
./ drf_create_token <username>


./ showmigrations

# Reset
./ migrate appname zero --fake

# Login and drop tables
./ dbshell

drop table cases_case;
drop table cases_relatedcase;

drop table references_casereference;
drop table references_casereferencemarker;
drop table references_lawreference;
drop table references_lawreferencemarker;


# All tests
./ test

# Specific app tests
./ test oldp.apps.cases --keepdb


# run in production shell
from django.core.cache import cache

# Empty specific cache

# Empty all cache




Once the sitemaps application is added to your project, you may also ping Google using the ping_google management command:

python ping_google [/sitemap.xml]

Generate UML diagram from models

apt-get install python-pygraphviz
pip install django-extensions
# add 'django_extensions' to INSTALLED_APPS in
python graph_models trees -o test.png