Skip to content

Instantly share code, notes, and snippets.

@celine-m-s
Last active November 13, 2017 14:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save celine-m-s/6e7d79322f492ac9590472aff3ccc1ff to your computer and use it in GitHub Desktop.
Save celine-m-s/6e7d79322f492ac9590472aff3ccc1ff to your computer and use it in GitHub Desktop.
# run server
./manage.py runserver
# Interactive shell
./manage.py shell
# don't forget to import the objects you need (models, ...)
# eg from polls.models import Question, Choice
#################################
########### Generators ##########
#################################
# Start a new Django project
# Add _project at the end so it's easier to see the difference between project settings and apps.
django-admin startproject projectname_project # you can also use django-admin.py
# Add a new app
django-admin startapp appname # you can also use django-admin.py
#################################
########### Migrations ##########
#################################
# Make migrations
./manage.py makemigrations # for all models
./manage.py makemigrations appname # for one app
# Run the migrations
./manage.py migrate
./manage.py migrate appname
# See the SQL output for a migration
./manage.py sqlmigrate appname 0001
# Check if anything is wrong in the project
./manage.py check
# See migrations
./manage.py showmigrations appname
#################################
######### Django Admin ########
#################################
# Create a new administrator
./manage.py createsuperuser
# you can now go to http://127.0.0.1:8000/admin/
#################################
############ Tests ############
#################################
# Run tests
./manage.py test # all tests
./manage.py test appname # a specific app's tests
#################################
########## Fixtures ###########
#################################
# Create a dump of the actual DB
./manage.py dumpdata > all_db.yml
# Create a dump of the actual DB
# for a specific app
./manage.py dumpdata store > store.yml
# Restore a dump to the DB
# Doc: https://docs.djangoproject.com/en/1.10/ref/django-admin/#loaddata
./manage.py loaddata store.json
#################################
########## Postgresql #########
#################################
# Create a database
createdb db_name
# Delete a database
dropdb db_name
# Launch a server Mac
# As per https://stackoverflow.com/questions/7975556/how-to-start-postgresql-server-on-mac-os-x
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
# Stop server Mac
pg_ctl -D /usr/local/var/postgres stop -s -m fast
#################################
############ Docker ###########
#################################
# Launch the "command" line of docker-compose.yml
docker-compose up
# Launch docker-compose.yml build script
docker-compose run web django-admin.py startproject website_project .
# Launch Django command
docker-compose run web ./manage.py migrate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment