Almost done with the first Module and expanding my knowledge and efficiency working with the Django Web Framework.
This week we had our Module 1 practice exam. This exam consisted of 35 questions covering Django and solving functions in Python. Afterward, we started our minimal viable project, Project Alpha. The goal for Project Alpha is to develop the backend for a task manager application using the Django web framework. This process was done in 17 steps and can be seen in full detail in my video documentation of this project. This week was full of a deeper understanding of the Django Web Framework, python problem solving, and even attending a workshop by
Codesmith to learn about Classes and Objects in Javascript. Lets me present to you my learnings for the week. Challenges and what I'm focusing on for next week are at the bottom of the article.
Learnings for the week
How does the Django model classes help a developer for writing a Web application?
- Connects our Django application to our database
- Organizes our data and connects different models
- Allows us to utilize forms to input data
- Allows us to type our data and set limits
How does a developer organize code in Python?
- Using repositories. This allows us to have a snapshot of our code and store it in the cloud with the ability to have multiple different lifestyles of the code as it has been developed on.
- Using functions. Allowing developers to make reusable pieces of code that can be called upon/executed whenever necessary.
- Using Modules. Allowing developers to create organized code that can be imported and exported into other files.
- Using packages. This allows developers to initiate a code quickly. They are user-friendly and enhance the user-interpreted code to execute smoothly in run time.
- Sub-packages. Allows developers to place packages inside a package folder. This is done using the init.py file name.
- Sub-modules. Allows developers to place the files inside the sub-package. (Reference the below image)
How do models, views, forms and templates in Django work together to make a working Web application that can show and accept data?
- Models function to define our data for our database to interpret and accept.
- Forms utilize the models to provide data to our database.
- Views allow us to carry out functionality that allows us to achieve CRUD (Create, read, update, and delete data in our database)
- Models, forms, and models work synergistically to produce what is displayed in our HTML template.
What function to use to add all numbers in a list together and also return none?
Sum() method
During coding interviews, ask about edge cases. Edge cases are scenarios if your input is an empty list. What should be returned? Should the function return 0? Take care of your edge functions at the very beginning. The initial data validation should be done first.
How to use the *args in Python?
“args” allows passing into a function a non-keyword argument. In the function itself, it is industry standard to use an “” before the parameter's name to pass a variable number of arguments. To note, the name of the argument doesn’t have to be args, and it can be anything. “args” is seen as a standard to use as the name when referencing an argument. The use of *args came into my learning this week when solving a python problem with “*numbers” as the parameter. The coding challenge was to solve a function that returns the sum of all its arguments. The inputs and expected outputs are the following:
Below is the function name and parameter given.
In python the use of the methods char() and ord().
For example, the char() method assigns a preset character from a set of the number range.
And the ord() method converts a character into an assigned Unicode integer for that character.
In Python, the use of the split() method.
Where each word in a string becomes its own list item. For example here is a split string function that I created this week.
How to create pairs from a list of items and return a list of pairs in consecutive items?
Note that if the list is odd, we don’t want to create a function that will return the last number in the list. For this function, we will add in our code a “look ahead.” This is where we write in our if statement to check and see if the following index is within our items list. It is saying that we have another item to pair with. Example function.
Joining strings with a separator.
Multiple strings exist in a list. We want to add a separator in between each string and be turned into one string.
How to display unique items from a list that has duplicates?
This is done by creating a dictionary and organizing in our code our key and value pairing. The following function will work.
What is a ZeroDivisionError and float(”nan”)?
ZeroDivisionError is built into python and is seen whenever a number is being divided by zero. In the world of mathematics, an infinite number is produced when dividing a number by zero.
How to solve the ZeroDivisionError? This is done by using a try except. For example.
And float(”nan”) is the equivalent of stating that we having missing value in the data and that it is not a number. In more technical reasons the
IEEE 754 (Institute of Electrical and Electronics Engineers) states that NaN as a float value.
What is casting?
I am referring to when you need to change all the items in a list to a str() or int(). This is also known as type conversion. It results in converting the data type to another data type.
What is negative indexing?
This is done so that we can target from the end of a string. Using the syntax of “[start:stop:step]” And when we say values[-1] this means we are counting from the last item from a list of items. This
article from tutorialspoint high list in-depth the various syntax combinations
Negative Indexing is used to stop and step. and how to reverse a string with negative indexing.
Will Django create an automated related_name in our models ForeignKey creation?
This is found in the Django documentation underneath the Following relationships “backward” section that Django by default will create a related name by default if not specified. It will do this by lowercasing your model name and adding the text “_set” to it. Using a user-friendly name following the input of “related_name.”
When creating fields in our Django model using the Charfield(), it is always required to add the parameter of how much the max length of the character field will have.
In addition, we don't need to add a parameter in our fields when using DatField(), PositiveIntegerField(), or EmailField().
How to delete a filed in our Django model?
This is done using Cascade deletes. Using on_delete=models.CASCADE will delete the object containing the ForeignKey that has been created.
When the “on_delete” is set to PROTECT or RESTRICT this will not delete the related items as well as CASCADE will do.
What is the parameter to add to the field in a Django model to update a field every time there is a change to the record?
This is done using the ".auto_now" attribute, which is useful when you want the field to automatically set the new field every time the object is saved. When using the ".auto_now_add" attribute, the field will be set to the current time when creating the object for the first time. Refer to the specific Django documentation for more information can be found
here for this.
Python has a linear approach.
Python follows a top-to-bottom order. This becomes apparent when working with your database, updating a variable after saving and not saving your update. Your variable will be that new output you added for that variable, but the database will not have the updated variable because it hasn’t been saved yet.
What happens in Django if a field attribute is commented out or not included?
Django will respond with an error about not having a field or no input for attributes.
Why do we use form.save(False) in our create view function in Django?
This is done to create a pause to allow us to add more information before we send this information back to the database.
If we want to include information to be viewed on our HTML template, where does that come from in Django?
This comes from our passed-in dictionary called context in our created function from our
views.py folder from our app folder. This will provide all the information we want to display on our template page.
Codesmith -JavaScript the Hard Parts: Classes and Prototypes
This is one of the challenging workshops in the JavaScript complex parts series. Every week Codesmith offers free workshops online and in person. This class had over 70 people on a Zoom call to learn about Classes, Prototypes, and Object-oriented programming. This was well-produced, and the content was precious. It highlights in depth the technical communication for JavaScript underneath the hood. It references how the language works with the call stack, improving memory efficiency, global execution context, garbage collection, bracket notation, dot notation, global execution, and thread of execution.
Reid Klarsfeld is one of the best instructors I have seen and learned from when teaching how a coding language works under the hood and getting the audience involved and engaged. Highly recommend you connect with him on Linkedin.
Challenges for this week:
- I am facing errors in the Django project when creating new files, viewing functions, or registering new paths. I wouldn’t be able to have the correct way identified on the response side of my application correctly displayed in the web browser.
- I am developing effective pseudocode on specific Python problems to solve them effectively and efficiently. However, I am getting better at them and solving them.
- However, I'm improving daily with a deeper understanding of dictionaries and for loops.
- When going back into the Javascript world, having to recall concepts like the call stack and the global execution context and be able to understand deeper the object-oriented programing that is commonly used in Javascript and Python.
Focuses for next week
Monday is our Module 1 test, so I am preparing for my main weakness: solving functions by Monday for the exam. Then I shifted my time to networking, improving my LinkedIn presence, and researching companies and remote opportunities. My girlfriend's cousin is a software engineer in Colombia, and I'm hoping to meet him to talk shop and get his thoughts on the industry in Colombia. Also, my girlfriend and I will be heading to Medellin from March 19-26, and there, I'm hoping to meet another classmate starting in the Hack Reactor program in March. I used ChatGPT for the first time today when my girlfriend asked me for a technical PowerPoint presentation. I searched for a solution for numerous speakers working on a large PowerPoint file to prevent events. I was very impressed with the steps and documentation that responded to my specific questions, and this is a tool I plan on learning more about how to interact and see where I can extract value from. In addition, I am amazed at how fast it produced the seven videos I requested to learn about angels in the catholic religion, which are all under ten minutes. Please see the photos from below.
Lastly, I want to update you on my baptism process here in Santa Rosa de Cabal. We have switched churches and fathers. The father we met with last Sunday is named Andres, and he spoke very clearly and was personable. We chatted about the world history of religions and the different types of christianity and catholicism. We were later given homework to research angels in the faith and presented our notes to him the following week. Nonetheless, an experience and learning and understanding the culture deeper here in Colombia as most of the country follows a catholic faith. Moving on to next week! Ciao for now!