Learn Python Django | Aha moment

Learning a programming language is not a pleasant activity at all. We will certainly face hard times and want to quit learning. We feel like everything doesn't make any sense to us. But in another momentwe feel so content with new things we learned. Only persons with persistence and determinations could endure this roller-coaster ride. In some moments this process seems like a never-ending journey.

I have experienced this situation for the last two years or so. In my earlier postI wrote about my struggle learning to code until I thought that I would never become a programmer. 

When I finally found 'Learn Python the Hard Way' website and grasp the basic concept of Python Language, I became confidence. I believed that I could dive in into programming. However, I haven't found a learning pathway even when I have decided that I want to be a web developer and data scientist.

When I did a little research on google, I came across freecodecamp.com (now freecodecamp.org). I was a bit hesitant to try this platform since it uses JavaScript. When I didn't find any good resource of the Python tutorials, I came back to this interactive learning site and start learning Front End Development.

Everything went smoothly when I worked on HTML, CSS, Bootstrap and jQuery materials. And then the first hurdle stroke me when I had to finish the second project, Build a Personal Portfolio. I remember that this project made me escape this website for about a month.

I didn't remember how, but I found a YouTube channel which did the walk through tutorial solving all FreeCodeCamp challenges. The tutorial helped me solving project challenge. That was my turning point in learning a programming language. 

I felt so comfortable learning to code from video tutorials than books or documentation. From that moment I gained traction to keep doing Freecodecamp challenges. Every time I did a new Freecodecamp challenge, my understanding of  front end web development got better. 

I have to be honest that I finished most of challenges and projects by following or modifying the tutorials. But in the last two projects (Project #9 and #10), I could finish it  with my own idea and script. And this was my first experience with 'Aha moment'. 

The Front End Development certificate boosted my confidence learning web development. Despite there are two other certifications (Data Visualization and Back End Development) from Freecodecamp (now they have six certifications), I decided to go back to Python programming and started learning flask framework. 

Soon I was able finding a good flask tutorial on YouTube and started following the channel right away. I completed the tutorial in less than two months. I felt that flask is less challenging for me at that time. I admitted that I haven't fully understood this framework but I didn't exactly know why, I decided to try learning Django instead of deep dive into flask. I found later that I was a bit regret with this decision. I should have mastered flask before touching Django.

I learned about #100DaysOfCode challenge when I finished a Django tutorial from YouTube. I jumped into this challenge right away by doing another Django tutorial video on YouTube. This challenge brought me to the basic understanding of how does Django work. Freecodecamp and #100DaysofCode also took me to awesome programming communities in Facebook, Twitter, and Telegram. 

And those communities introduced me to more discounted or free resources like PactPub and Udemy. But one thing still missing, I haven't been able to build a website by using Django from scratch. I didn't fully understand how Django models work, it's all seem like magic to me how queryset picks up data from the database and Django views presents it to the front end (Django template).

I went through another hard time during the period I tried finishing the Django eCommerce tutorial. This tutorial is so complex and incorporates advance materials such as asynhcronous page loading, stripe APIMailchimp API, and data analytic. 

Sometime I felt that I was bewildered by these new materials and I thought I would never understand how queryset in Django model works. Fortunately, coding has become my new habit and I kept pushing myself following the tutorial. But for several months, dozens of questions filled my head. Will I finally be able to Understand Django? Will I be able to build web by using Django 2 and Python 3? What concept that I haven't understood?

Learn Python Django | Aha MomentEventually the moment was coming. I found that 'Aha Moment' in the end of the Django eCommerce tutorial. The concept that I didn't understand was 'Model Manager' and 'Overriding Parent Method". And it's a bit silly because there has been a video in the beginning of the tutorial that talk about Model Manager.

 Soon I search for YouTube videos about Model Manager and Object Oriented Programming (OOP) to refresh how overriding parent method really works. Suddenly I realize that I haven't really master Python especially Python 3. Despite the fact that I have learned a concept in Python that doesn't mean that I fully understand it and can use it in a real life problem.

I need about nine months of learning Django to come to this realization. I looked back to the difficulties I encountered. What made me took quite long time to understand Django? In my opinionhere are some mistakes that I did by jumping into Django before knowing Python really well:

1. I didn't really know about Modular Programming

When I learned Python from a book, I followed writing codes in a file and then run it. In some parts, I did import libraries such as random, math, time and others. But I didn't really notice how it works nor try to find out where those libraries were stored and what inside it.

I had to pay this unawareness with confusion during my first four months learning Django. Every time we start a Django project and an additional app, we will find files like urls.py, models.py, views.py with a line of code importing a function from somewhere.

from django.urls import path

from django.shortcuts import render

from django.db import models

The functions and classes we imported would increase into a long list like this:
from django.http import Http404
from django.views.generic import ListView, DetailView
from django.shortcuts import render, get_object_or_404
from .models import Product

from anotherapp.mixins import ObjectViewedMixin
from firstapp.models import Cart

I thought there is only one way to understand it, by memorizing it. But one of Django tutorials I followed taught me how to explore Django packages and its functions and classes. We can also learn about Django modules from this Index.

|   shortcuts.py
|   __init__.py
|   __main__.py
|   |           
|   +---urls
|   |   
|   +---admin  
|   |           
|   +---admindocs
|   |           
|   +---auth
|   |           
|   +---gis
|   |           
|   +---humanize
|   |           
|   +---postgres
|   |           
|   +---redirects
|   |           
|   +---sessions
|   |
|   +---sitemaps
|   |           
|   +---sites
|   |           
|   +---models

2. I haven't master regex

Before Django 2.0, urlpattern in urls.py uses regular expression (regex) to determine the pattern of a path of a page. My first Django version that I learned was Django 1.9, so I have to deal with regex every time I set up a URL pattern for a view that I made. The most confusing pattern was a detail page pattern. This urlpattern must incorporate all kind of different name from a field of database. It could be name of products (slug), months (int or char) or years (int), or others. 

When you can't make head or tail of this pattern, it will slow your learning pace down. There is no other option but to look back to Python regex tutorials and study it. One source that helped me to discern regular expression was web that provide cheat-sheet. Whenever you feel confused with an expression, just open that sheet and try to find it's meaning fast.

3. I had a little knowledge about database

Django has a default object-relational mapping layer (ORM), which enables users to interact with application data from various relational databases. When I learned this feature for the first time, I was so delighted because I though that I didn't have to learn about relational database anymore, yeayy. I learned MySQL several times but nothing stick in my mind. 

But I was wrong. Yes, Django ORM makes developers' lives much easier. However, this doesn't mean that we can skip learning relational database. Django omit the hustle of creating a database, tables and database connection to our program. Nonetheless, we must have a good understanding of how data in different tables are related and most importantly how we design it. If we can't determine the primary keys and relationship type, our database will be a mess.

Once again I had difficulty digesting Django tutorials when it involving relational database. Everything started to became clearer when I watched Django tutorial from CodingEntrepreneurs Channel on YouTube. In TryDjango 1.11 (and other videos) Justin Mitchel, the tutor, explained the relational database by using Python shell from Django (run python manage.py shell on the terminal). I am not going into detail about this right now. You better watch yourself the video or his latest videos.  

4. I didn't understand a thing about OOP

I think this is my ultimate mistake learning Django without enough understanding of OOP. I knew my little understanding of OOP would become a problem for me learning Django. But I didn't expect that this would make my learning journey took such a long time. 

I learned OOP for the first time from Learn Python The Hard Way book, and I didn't understand anything. I tried to learn from Python 3 Object Oriented Programming book from PacktPub, but I couldn't even finish the second chapter. I took an online course on edX titled Introduction to Computer Science and Programming Using Python

I thought I knew almost everything about Python OOP from this course because It has a really good OOP material. But yet again I kept on struggling digesting Django eCommerce tutorial from Udemy.

Soon after I realized that I didn't really understand about inheritance concept, particularly on Django Model Manager, I search for OOP tutorials on YouTube. I discovered that Python OOP Tutorials - Working with Classes by Corey Schafer was the best OOP tutorial I could find on YouTube.

Once I could discern Django materials and finished Django eCommerce tutorial, I started to build my own project. I will try to share my experience building my project in the next post.