I have been meaning to build my skills in some areas for quite some time, Python, traditional backend frameworks and a bit of full-stack development being a few of them. I decided on building a simple weight-tracking website to learn these things. It had been tossing about in my head for a lot of time, and finally I decided to sit down and start coding it today.

Day 1 Challenge 1

The first thing to do was to create a directory to store all the code in. Here was the first roadblock I hit, what should the project be named. After contemplating and thinking a lot on it (read 3 minutes max) I decided to go with “Wracker” as it could be seen as a short for “Weight Tracker” and also it is a pun on the word “Wrecker” which I just found hilarious.

Day 1 Challenge Virtual

Up next was me wanting to install the dependencies for the project without them muddying up my system-wide python packages. I knew of virtualenv and have banged my head enough in the past that it only took me 3 tries before I had it nailed down.

Day 1 Challenging Structure

Since I wanted to use Django framework for this project and I haven’t ever used it before, I went to their official getting started guide and was left with a file structure looking something like this after initialising my project.

- Projects
  |- wracker
     |- .gitignore
     |- wracker
        |- manage.py
        |- wracker
           |- __init.py__
           |- asgi.py
           |- settings.py
           |- urls.py
           |- wsgi.py

Here I tried running the commands from getting started guide inside a pre-made directory for my project. I could not understand why it needs to create 2 separate subdirectories named the same as the project. This is something I tried understanding multiple times during the day, and we’ll back come to it later.

Challenge Post the SQLite

Django by default uses an SQLite database for storing data, but I wanted to use Postgres. I had already setup a docker-compose.yaml file to provision me a postgres database running inside a docker container. While initially the configuration part in Django for Postgres was a bit confusing, I was able to get it working after a bit of fitting in multiple pieces together. I also learned how to use environment variables in Python while dealing with this.

Challenge of Looking Good

I also wanted a code-formatter for Python and had heard about this one called black. Went to the official website, learnt how to use it and then integrate it locally with wracker.

Challenge of the Day

After looking at all this I would give “Challenge of the Day” award only to the project structure. While none of the official documentation clearly call it out that you need to pass in . as the directory to your django-admin startproject I did find an article online that clarified it.

Things I learned/solidified today

  • Using virtualenv to keep dependencies separate in Python
  • How to export your dependencies as a requirements.txt file
  • Usage of environment variables in Python
  • How to create a Django project with reasonable directory structure
  • Formatting python code using black
  • Integrating PostgreSQL with Django instead of the default SQLite database