Skip to content

Instantly share code, notes, and snippets.

@bartdorsey
Last active October 4, 2022 21:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bartdorsey/0a083d5b24bff4ebc1b213c761444f5f to your computer and use it in GitHub Desktop.
Save bartdorsey/0a083d5b24bff4ebc1b213c761444f5f to your computer and use it in GitHub Desktop.
Django Speedrun Part 1

Django Speed run

In video gaming culture a speed run is where someone tries to play a video game all the way through as fast as they can. Turns out this is a great way to practice! So we are going to be setting up a basic django app from scratch as fast as we can.

We want to get to the point where we do the following as fast as possible.

  1. Create a project folder
  2. Create a virtual environment and activate it
  3. Install Django
  4. Create a Django Project
  5. Create a Django App
  6. Add the Django App to the Project
  7. Do the initial migrations
  8. Add a Simple Model.
  9. Add that model to the admin
  10. Migrate the simple model
  11. Add a superuser
  12. Start the Django app and go to the admin and add a model.

Note! Writing a script or automation to complete the steps faster is cheating!

You get as many chances as you want to improve your time! Post your best one in Slack once you are happy with it!

Detailed instructions

Level 1

Start a timer!

Create a project folder (If you are doing the speed run more than once, create a new folder each time)

cd projects

mkdir django-speedrun

cd django-speedrun

Level 2

Create a virtual environment and activate it.

python -m venv .venv

macOS: source .venv/bin/activate

Windows: .venv/Scripts/Activate.ps1

Level 3

Install Django

pip install Django

Level 4

Create a Django Project (Don't forget the dot!)

django-admin startproject speedrun .

Level 5

Create a Django App (name it whatever you want)

python manage.py startapp myapp

Level 6

Add Django to the Project

Open your directory in VSCode

code .

Then edit INSTALLED_APPS in settings.py to add your app.

Level 7

Do the initial migrations

python manage.py migrate

Level 8

Add a simple Model

Edit models.py in your app and add a model class with a single field

Make sure to add a __str__ method!

Level 9

Migrate the simple Model

python manage.py makemigrations

python manage.py migrate

Level 10

Add the model to the admin.py file

Edit the admin.py file to import your model and add the admin.site.register() call

Level 11

Add a super user

python manage.py createsuperuser

Level 12

Start the Django app, local it in your browser, to to the admin page, login, and add a new instance of your Model.

python manage.py runserver

Stop the timer, because you are done, then share your best score in Slack!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment