Categories

A Simple & Effective Django Honeypot Form Field

Understand the basic concepts behind honeypot form fields and learn how to implement a simple Django honeypot form field 🍯

Categories

Changing a Django model’s primary key with migrations

Recently, I took on the task of internationalizing a Django app. The app included the following two simple models for tagging user Profiles with a set of pre-defined Tags: “Wait a minute…”, I thought to myself while scrolling through the models.py module for the first time. “How am I supposed to add a translation for […]

Categories

He or She? Or: The basics of (binary) classifier evaluation

Of all the amazing scientific discoveries of the 20th century, the most astonishing has to be that “men are from Mars, [and] women are from Venus”. (Not that the differences weren’t obvious pre-20th century, but it’s always good to have something in writing.) If indeed the genders do originate from different planets, then surely the […]

Categories

Where to define and instantiate associated models in Django

For the sake of example, let’s consider the following UML diagram describing two model classes and how they are interrelated: We can see that there are two classes, User and UserProfile, with a one-to-one association between them. That is, each instance of class User is associated with one and only one instance of UserProfile and […]

Categories

Guessing multiple extensions from dotted filenames in Python

How to extract suffixes from filenames with Python Defining a guess_extensions(filename) utility function that extracts extensions from a filename Recently I was dealing with filenames of the following form: 3a1d3614.2020-09-27.json.gz. That is, the filenames consisted of four parts: an alphanumeric ID, a date, and two extensions separated by dots. Python offers at least two built-in […]

Categories

Diagrammatic Icons and their Motivations: Central Concepts and Examples

Note: What follows is a linguistic essay I wrote during my time as a student pursuing a master’s degree in computational linguistics. I stumbled over it a few days ago while going through some old data. Given the general scarcity of information about the topic of iconicity, I’ve decided to publish it here. Despite its […]

Categories

Serving your Django app’s static & media files with S3 and CloudFront (super fast & easy!)

The following steps will leave you with an AWS setup for serving your app’s files via xyz123.cloudfront.net URLs: Create an S3 bucket (e.g. my-app-bucket-staging) and leave all settings at their defaults Open the newly created bucket and navigate to Permissions → CORS configuration Create an XML CORSConfiguration that defines from which domain the contents of […]