Post #84 written by Khodok in Blog Updates
More than one!
Posts can now be in multiple categories, which is way better than one because some posts belong in two, this on for example works as an update AND a Friction Log.
What changed
Posts can now be in multiple categories, which means if they are, all their categories will be shown on their category list, and if 2 categories have the same post, both categories get a post count.
Category RSS
Requesting the RSS feed of a category still shows all the posts in this category, and if a post is in two categories, it’ll be in both RSS feeds
Friction Log
Field change
I had to find a way to go from a ForeignKey to a ManyToMany in my models without losing everything, it took faster than I thought it would, and I learned something new!
I used this if anyone ever encounter this problem https://ponytech.net/blog/convert-foreign-key-many-to-many-using-django-migrations.
Dumbery
I pushed everything, started writing this post and suddenly remembered that while I was working on this idea I thought about being careful not showing in the category lists of a post the ones that are marked as Private (now Withdrawn) if the user isn’t logged in and an Admin, but I forgot to do it, so I then had to fix it, and it was a struggle, I had to check if the second to last item in the loop was a private category and if it was then don’t add |
at the end and if it wasn’t add it… it would have been easy if I actually spelled the problem like I just did, but at first I just tried a few ways to do it… and it took me around 30-45 minutes, when I did spell the problem out, I fixed it in a minute… I also now know how to check a value of the last item in a forloop, by doing while I’m in the second to last iteration, else forloop.last will just check the last and won’t take in consideration any other conditions (trust me… Django (jinja) templates can be really confusing…)
Reading this on May 1 2022 and tbf… I was dumb af