Last active
October 30, 2022 01:34
-
-
Save carloocchiena/d6f98b2bda969dbd4a37c124d26902a6 to your computer and use it in GitHub Desktop.
A simple list of django CLI commands you may need whenever starting up a new project
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Django Cheatsheet | |
# start a new Python env (with Anaconda) | |
`conda create -n my_env pip python=3.8.8` # insert your fav python version here | |
# activate Python Env | |
`conda activate my_env` | |
# install Django | |
`pip install django` | |
# create Django project | |
`django-admin startproject my_project` | |
# start new Django app | |
`python manage.py startapp my_app` | |
# prepare the migrations: | |
`python manage.py makemigration` | |
# migrate: | |
`python manage.py migrate` | |
# create a superuser | |
`python manage.py createsuperuser` | |
# see SQL commands run by django: | |
`python manage.py sqlmigrate first_app 0001` | |
# run Django shell: | |
`python manage.py shell` | |
# examples of queries you can run in the shell: | |
`MyModel.objects.all()`, | |
`MyModel.objects.filter(name='my_name')`, | |
`MyModel.objects.filter(age__gte=20).all()`, | |
`MyModel.objects.filter(first_name__startswith="c").all()`, | |
`MyModel.objects.filter(first_name__startswith="c").exclude(age__gte=20).all()`, | |
`MyModel.objects.order_by('age').all()` | |
# run Django db shell: | |
`python manage.py dbshell` | |
# Useful commands for the db shell | |
`.schema` | |
`.tables` | |
# run Django tests: | |
`python manage.py test --verbosity=2` # verbosity add more details, goes from 0(quiet) to 2(verbose) | |
# run Django server | |
`python manage.py runserver -port=8000` # specify a port if needed | |
# collect all statics file in a folder | |
`python manage.py collectstatic` | |
# make a requirements.txt file | |
`pip list --format=freeze > requirements.txt` | |
# group all the application and output database diagram into PNG file | |
`python manage.py graph_models -a -g -o imagefile_name.png` | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment