Skip to content

Instantly share code, notes, and snippets.

@mohapsat
Last active August 28, 2018 08:21
Show Gist options
  • Save mohapsat/0fcd91729031105d6a52f2b8ed1aa557 to your computer and use it in GitHub Desktop.
Save mohapsat/0fcd91729031105d6a52f2b8ed1aa557 to your computer and use it in GitHub Desktop.
Django admin and manage commands
# to make migrations on models are defined
python manage.py makemigrations
# review sql for the migration
python manage.py sqlmigrate <app_name> <migration_number>
e.g. python manage.py sqlmigrate boards 0001
# Django shell to play with the db
python manage.py shell
https://simpleisbetterthancomplex.com/series/2017/09/11/a-complete-beginners-guide-to-django-part-2.html
Operation Code sample
Create an object without saving
board = Board()
Save an object (create or update)
board.save()
Create and save an object in the database
Board.objects.create(name='...', description='...')
List all objects
Board.objects.all()
Get a single object, identified by a field
Board.objects.get(id=1)
# to exit
exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment