Nearing the Finish Line
Blog Home

Nearing the Finish Line

June 28, 2019 |  Categories:  Development  

What a tremendously exciting day it's been! And it's not even 3 o clock yet! Much to my delight, I was able to find a quick and relatively straightforward solution to the image pathway issue I was experiencing with my Project model. Yesterday, I'd been trying to use the FilePathField model to assign images to my projects on the admin site. But as I described in my last post, I wasn't able to make the images I associated with each object in the model class render on the HTML template. To work around this issue, I decided to try a new approach: uploading media files. Typically, the media directory within a Django project is used to host user-uploaded files and data for a site. Because I will be the only person to ever modify this site, I thought I didn't need to bother with configuring this part of my settings. But as I discovered, doing so solved this major headache rather painlessly. I started by creating a directory titled 'media' within the main branch of my Django project. I then added the following lines to my file: ![Establishment of media directory][1] These two lines told Python where to look when trying to access necessary media files. Then, I modified the Project model class in the file in my projects directory by replacing the FileFieldPath model with the ImageField model: ![Code changes to][2] The only argument for this new model, upload_to='images/', told Python to upload the image I designated on the admin site to the images subdirectory in my media folder. Then, crucially, I was able to successfully link each project to its respectively chosen picture using: src="{{project.image.url}}" You'd probably laugh at me if you could see how excited I got when this finally worked. With that massive monkey off of my back, I spend a while standardizing and cleaning up the format of my project portfolio, and even attached URLs to each project that link to the source code on my GitHub! I'm really proud of my work on this aspect today, and was extremely encouraged by how quickly I'm beginning to grasp the structure of Django. The second main focus of my efforts today was on implementing pagination on my blog's homepage. As I intend to continue writing these posts well into my programming journey, I needed a way to split up the collection of all my entries so they didn't print out on my blog index as one massive list. After bouncing between a few different tutorials, I finally found one by this Finnish guy Salumi Natri that simple and easy to understand. First, I had to modify the blog_index function in my file for the blog app. Fortunately for me, Django has a built-in paginator app that made the back end implementation of this feature fairly straightforward. Here's what my code looked like: ![Code changes to][3] With the hard part out of the way, I just had to implement this on the front end, and I had Salumi's tutorial and Bootstrap's documentation to help me out. As Salumi was using a different styling CDN than me, I ended up using a blend of his method and the basic pagination bar found on Bootstrap's documentation website. Here's what my code looked like in my HTML template for my blog's homepage: ![Paginator implementation][4] At this point, the only things I can think of to do before getting my site ready for launch are revise the "About Me" section one more time, remodel the show/hide button on my homepage, and test everything twice over to make sure it's ready to go. I'm so, so excited to have this site up and running, and if I can have it online by the time I leave for Colorado next Wednesday, I'll be ecstatic! -Joe [1]: [2]: [3]: [4]:

Leave a comment:



I'm Joe Pickert, and welcome to my blog.

Here, you can find a collection of my thoughts both tech-related and otherwise.

If you find something that interests you, please leave a comment! I'd love to hear your thoughts and feedback!