TIL - Today I Learned

Everyday’s a day to learn something new.

Here’s a list of all the little things I learn every day.


Using Signals to Clean Up My Mess in Django

While trying to cascade deletes of Droplets when I delete the parent Class they would have been associated with in DigitalOcean Classroom, I attempted to overwrite the delete method. This only works part of the time, so I instead turned to signals, specifically the post_delete signal. Now no matter what triggers the delete on the Class, my Droplets are cleaned up and deleted from my account. I plan to use signals more for the creation process as well.

@receiver(post_delete, sender=Droplet)
def droplet_delete(sender, instance, using, **kwargs):
    droplet = digitalocean.Droplet(token=settings.DO_TOKEN, id=instance.droplet_id)
    try:
        droplet.destroy()
    except NotFoundError:
        pass

Equivalency Statement In Hugo

Today I wanted to check if a page on this site was a TIL page and modify the list to not include a link if it was. To do this I used conditional statements in Hugo to check for equivalency.

{{ if eq .Type "TIL"}}