Below I describe my first week of the #100DaysOfCode challenge.
In the opening blogpost you can find out more about my Why, my goals and the rules which I set for myself.

Django installation and setup | Day 001 (2022-01-05)

started to install Django to build a real world application on the following technologies (decisions based on DjangoDocs, DjangoChat Podcast recommendations and foreknowledge):

  • web server: none (yet) – to be done before deployment
  • database: MySQL + mysqlclient (DB API Driver) + XAMPP development environment

At first I wanted to use „MySQL Connector/Python“, because I am on Windows (which seems to make issues when used with mysqlclient) and the Python connector includes their own adapter to provide djangos‘ ORM access to the database.
However I had a hard time figuring out how to start with django and MySQL at all.
Then I found that most of the search engine-recommended tutorials for django and myqsl are mostly based on mysqlclient.
Therefore I now think, that I am going for mysqlient since it’s also the way django docs recommends.

  • tests: not yet decided
    • according to Python docs: pytest framework has a „lighter-weight syntax“ than the built-in unittest framework

virtual environment | database: MySQL server| project setup

  • initialized a virtual environment (venv)
  • installed django into the venv
  • created a requirements.txt for the venv
  • installed „MySQL Connector/Python“ (probably don’t need it in the future anymore since I assume to switch to mysclient)
  • setup local MySQL server
    • installed mysqlclient (and did not encounter an error on installation… as expected🤔)
    • Thanks to El-Djangoistas video I was able to setup: MySQL server, mysqlclient installation and connection to django
    • download and install xampp
  • started django project
  • connected django project to local MySQL database (see above)
  • created superuser
  • adjusted timezone settings
successful installation process of mysqlclient on the windows command line (CMD)
mysqlclient installation surprisingly worked on my windows machine 🥳🎉

Build Django tutorial app, based on MySQL | what’s next?

OR

  • … build a new django project from scratch using the same approaches (for practice).

App creation in Django | Day 002 (2022-01-06)

  • created an app inside django project
  • recreated database and app after running in recursion error
  • created basic view
  • connected view to URLconf
This is the first visual result of the index page which I built for my django application
This is the first visual result of the index page which I built for my django application🤓

django models – the first approach | Day 003 (2022-01-07)

Actually I thought that I could already inspect the models from the shell that day…

tinker with the django shell – motivated

I really wanted to tinker with the models and define my first objects from the shell.
Later that day I therefor went on coding some more time until I reached the mentioned goal:

  • continue model creation
  • first few database migrations to local MySQL database (with defined models)
  • finally created Ad objects from the Django shell – based on models defined in the project code🎉
  • started to tinker around with my created objects using the django shell aka. database API
tinkering with defined objects in the django database API
tinkering with defined objects in the django database API

objects in database| Day 004 (2022-01-08)

  • add __str__ to models (for visualization in admin interface)
  • add default values to models‘ dates
  • define publishedRecently function in Ad model (to have a function as in djangoDocsTutorial)
  • edit DateTimeFields
  • set expiration time to 30 days from time of ad-creation
  • went through database migration cycle several times (check, makemigrations, migrate)🔁
  • went back in djangoDocsTut to create a Comment model, which is meant to have a relationship to the Ad model (purpose: having two models with relations)
using the check, makemigrations, migrate comments from the command line to update the database of the django project
using the check, makemigrations, migrate comments update the database from the command line

At that it was really laborious work to repeatedly create objects in the shell to test their functionality… then alter the model classes, migrate the changes to the database, start a new shell, test again…
Hence I was wondering whether it would make sense to write tests which automate the creation of default objects from the shell to test the models.
On a later day I realized that the object creation is already way easier if you have the admin interface.
But I am still wondering whether it makes sense to write automated tests to simply test the functionality of my models?

amend models and learn test writing | what I thought would be next

  • amending my models (purpose: having two models with relations)
  • learn to write tests for shell creation and testing of models (goal: standardize testing and save time when testing new, small model changes)
    • Does this make sense? Or should it be avoided by using the admin in the future (which makes it easier to create models than creatinf them in the shell every time)

admin interface for django project| Day 005 (2022-01-10)

  • add properties for Comment model (including OneToOne relation to Ad)
  • add some ideas in freeplane mindmap
  • create admin site

Relationships in Django – differences between ForeignKey, ManyToMany and OneToOne

At that time I was wondering:
What’s the difference between ForeignKey, Many-To-Many, Many-To-One and One-to-One? And how to access the different fields from the shell to test their functionality on implementation?

an insight into the admin and the first few objects
an insight into my admin and the first few objects

django objects visually in the browser window| Day 006 (2022-01-11)

  • create sketches for views for basic functionality (main page, ad search, detail pages, create ad)
  • edit URLconf to point to views
  • create template directory and file for index
  • recreate views with shortcuts (for 404 pages)

All of the above happend according to the basics from the Writing your first Django app“ tutorial from the Django Documentation.

Here you see my first few objects on the index page of my Django app
Here you see my first few objects on the index page of my Django app
these pages may be the most basic ones which I am going to implement in my app
these pages may be the most basic ones which I am going to implement in my app

ForeignKey for Many-to-One relationship| Day 007 (2022-01-12)

  • change relation between Ad and Comment to ManyToOne (ForeignKey)
  • play with objects in shell and admin (to investigate ForeignKey.on_delete CASCADE behavior)

On that day I found:

[CASCADE] also deletes the object containing the ForeignKey

Django Model field reference

I asked myself whether the object which contains „models.ForeignKey()“ is considered the object containing the ForeignKey?
If you delete it only itself will be deleted, right?
But when you delete the connected object (the one specified in the „to“-argument of ForeignKey()) the former will be deleted too, right?

definition of a Many-To-One relationship between two django objects
definition of a Many-To-One relationship between two django objects (here: Ad is the „to“-argument)

Django Template Language: learn how to use the system | What’s next?

At that time I was planning to learn the basics of the Django template system.

In the subsequent blogpost about the second week of my #100DaysOfCode challenge you can read how I really continued my journey.
Or find the collection of all my posts related to the #100DaysOfCode challenge.

Besides you are very welcome to follow my daily progress on Twitter.

What I’ve learned and accomplished this week – retrospective summary

  • STARTED to build my first real world application with django (kind of)🎉🥳💻🤓🎉
  • sketched a few ideas for the basic functionality
  • tinkered with models and objects in the database API of Django
  • learned the basics of object relationships in Django
  • set up a MySQL server for the first time
  • internalized the cycle for database amendment (check, makemigrations, migrate)

Taking up the #100DaysOfCode challenge too?

Are you also working on the #100DaysOfCode challenge?
Are you planning to take up the challenge in the future or did you already do it in the past?
What are your personal challenges on the way?