Day 27 Dev Notes
Busy night, so not much time to work on DJPress. But to keep my streak going, I updated the requirements for the Bus Times app.
Busy night, so not much time to work on DJPress. But to keep my streak going, I updated the requirements for the Bus Times app.
This was my first attempt at creating a template tag that loops through the categories for a post and returns HTML output. I need to avoid this getting too confusing, but for now you specific if you want the outer tag to be a <ul>
, <div>
, or a <span>
. You can also specify additional classes that get added to the link, which was already in place from the post_category_link
tag.
Added a new post category tonight, along with tests.
Next up, I need to think about looping through categories and how I can create template tags to deal with this.
Quick post about this macOS utility called LinearMouse I just discovered. It provides per-mouse configurations and lets me set the scroll direction on the trackpad separately than the scroll direction on the mouse. I'm not sure if I'm a special use-case, but this is the way I like it to be, and for some reason macOS does not let you do this.
More template tags and tests tonight. Not much else going on.
Once again, my AI friend has helped me out in a really unexpected and amazing way. For the last few nights, I've been adding new template tags to access various elements of the Post. My thinking is that you shouldn't need to know the field names of the model, you should just be able to type {% post_author %}
to get the author, or, {% post_date %}
to get the date.
But up until now, I thought that the only way I could do this, was to pass the Post object as the parameter so that the template tag knew which post author or date we're wanting. So the code ended up looking this: {% post_author post %}
to get the author, or {% post_date post %}
to get the date.
Just a small change tonight to keep my streak going. I added a post_content
template tag with a simple test, and all worked fine.
Most of my spare time today was spent playing with the new 3D printer.
Another small change tonight. I added a post_date
tag which simply returns the date, and also tweaked the post_author
tag to include some simple HTML.
More template tags and more template refactoring tonight.
I created a post_date_link
tag that displays a nicely rendered date with links to each of the date archives sections.
Tonight, I created a couple of custom template tags that can be used to display an author link and a category link. These tags first check if the respective options are enabled, and if they are, they return nicely formatted links.
More work on the DJPress URL structure tonight. It's slowly taking shape as I work it all out.
Did some more work on the mortgage tools app, with some form changes and tweaks to the scenario calculator. This was a good reminder of how Django forms work; it's been ages since I got down in the weeds with Django forms.
Recently I've just used crispy-forms to take care of the styling, but I took this opportunity to see how much work is involved in styling forms without the helper package. I think for a simple form like this with just 5 fields, it's not too bad. But crispy-forms is definitely the easier option.
I didn't post any code on the 9th May, but I did launch a whole new project after my last post about updating "My Django X", so I'm going to claim that as keeping my streak alive.
After that post, I wanted to see how quickly I could spin up a functioning project, so I took something I had been playing with in Excel and converted it into a Django app. This formed the start of a new project called "Mortgage Tools".
We will need to be making some decisions about mortgage rates soon, and I had been working on a calculator to compare scenarios. For example, let's say I could lock in a 24-month fixed rate at 6.75% today, or, I could get a higher rate of 7.29% for 12 months with the hope of the rate dropping in the future. The question is, what would the rate have to drop by to make it worthwhile.
This is the first calculator on the project, but now that I have it set up, I will add a bunch of other related calculators to help make these decisions.
But while this is going to be super useful, the main aim was to see how quickly I could spin up a project using the mydjangox
template. And I'm happy to say this was really quick and easy. The challenge now is to keep the template project up to date so that I can keep it useful.
I continued thinking about the URL matching for djpress
but didn't actually write any code for this. Unless, if you count playing with regular expressions, "writing code".
Instead, I took some time out to update my MyDjangoX
project, which is inspired by Will Vincent's DjangoX project.
More work on the URL structure. It's getting there, but is way more complicated than I'd like.
Still moving forward...
Big update to the URL structure this evening. I'll write more soon, but it's late now...
Just some tweaking of the PostHog integration this evening. Yesterday, I added the PostHog configuration and set it up so that the API key is loaded from the environment variables. But silly me - I forgot to add the environment variables to the Docker configuration, so they weren't being loaded into the app.
Today, I added the JavaScript integration to the Bus Times app. Still not sure what value it will add, but it's interesting to play with this stuff. Adding the JavaScript snippet posed a new challenge - I needed to include the API key in the JavaScript code, but I didn't want to hard code this in the template, and I didn't want to modify all the views to pass the key in the context. So with some help from my AI friends, I created a context processor, which isn't something I've used before in Django.
Just one minor change today. After listening to the latest episode of Django Chat, I decided to try out PostHog after a recommendation from Michael Kennedy.
I set up an account and installed the snippet on my Bus Times app. Still not sure if this will bring value, but the basic service is free and so I can try out and see what I think.
More refactoring again, renaming content
to post
in various part of the code. I also made a couple of small functional changes:
author_display_name
property to the Post model. All this does right now is show the first name if it's set, otherwise it shows the username, but this could be more configurable in the future.MARKDOWN_EXTENSIONS
. I may use this to help decide whether to load the Pygments CSS file since that's only needed if the codehilite
extension is used. But that's something to think about another day, since there are some other concerns with making this too configurable.Continuing to tweak the djpress package with the intention of moving into a standalone package. I thought I would start on moving it tonight, but I quickly realised that the packaging landscape is full of differing opinions and I need to do some more research on how best to do this.
The following two links seem to mostly agree with each other, so I will probably start with these:
But I also need to see how tools like Hatch, Flit, and others fit into the mix. Or perhaps that's overcomplicating things. Let's see.