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… Continue reading Where to define and instantiate associated models in Django

Featured post

Published

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… Continue reading Guessing multiple extensions from dotted filenames in Python

Published

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… Continue reading Diagrammatic Icons and their Motivations: Central Concepts and Examples

Published

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… Continue reading Serving your Django app’s static & media files with S3 and CloudFront (super fast & easy!)

Published

Busting caches with Django

In contrast to server-side code, client-side assets such as JavaScript files and static images are not directly deployed to where they are ultimately executed or displayed (i.e. the user’s browser). Rather, they are downloaded on demand whenever a browser retrieves a page for the first time. For sake of efficiency, the browser saves the retrieved… Continue reading Busting caches with Django

Published

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… Continue reading He or She? Or: The basics of (binary) classifier evaluation

Published

Avoiding query code duplication in Django with custom model managers

For a second, please imagine we are building the next big social network. We decide that our “revolutionary” new app shall allow its users to create profiles. Besides a mandatory user name and avatar, we consider a profile complete only if the user also supplies an email or physical address (or both). In other words,… Continue reading Avoiding query code duplication in Django with custom model managers

Published