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.
- Create a project folder
- Create a virtual environment and activate it
- Install Django
- Create a Django Project
- Create a Django App
- Add the Django App to the Project
- Do the initial migrations
- Add a Simple Model.
- Add that model to the admin
- Migrate the simple model
- Add a superuser
- 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!
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
Create a virtual environment and activate it.
python -m venv .venv
macOS:
source .venv/bin/activate
Windows:
.venv/Scripts/Activate.ps1
Install Django
pip install Django
Create a Django Project (Don't forget the dot!)
django-admin startproject speedrun .
Create a Django App (name it whatever you want)
python manage.py startapp myapp
Add Django to the Project
Open your directory in VSCode
code .
Then edit INSTALLED_APPS
in settings.py
to add your app.
Do the initial migrations
python manage.py migrate
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!
Migrate the simple Model
python manage.py makemigrations
python manage.py migrate
Add the model to the admin.py
file
Edit the admin.py
file to import your model and add the
admin.site.register()
call
Add a super user
python manage.py createsuperuser
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!