Aaron O. Ellis

Using Postgres Schemas

Schemas are a shockingly underappreciated feature of relational databases. With minimal overhead, they enable segmentation and isolation of tables within a database.

If you are interested in using schemas with Postgres, I recommend starting with the official documentation’s fantastic introduction. Although I will reiterate some of the introduction below, I will mainly focus on the exceptional behavior and issues that arise when using schemas.

Aggregation with django-filter via Proxy Models

The django-filter package adds a quick way to add URL parameter driven filtering to existing Django database models. For example, take the following model:

We can then use django-filter to quickly create a FilterSet class that wraps the above database model:

Python datetime.utcnow() Considered Harmful

The Python datetime.utcnow() classmethod is harmful and should be replaced with datetime.now(timezone.utc).

What makes utcnow() so dangerous? Although the function gives the correct time in the UTC timezone, the returned datetime does not include a timezone.

New York Times Misleads on COVID-19 Cases in Small U.S. Counties

Last week, the New York Times published an excellent series of visualizations tracking the COVID-19 outbreak in rural areas across the United States. At the very end of the article, however, they added a misleading table of the counties with the highest average daily case rates. The intent was to show that the most recent cases are hitting rural areas harder than urban and suburban areas of the country, and they did so by highlighting the counties with less than 10,000 people.

Allow Whitespace to be a Valid CharField Value in Django Admin

If you’re attempting to create a basic Django model that allows whitespace as a valid value, you may notice that it works as expected in the Django shell, but errors on the admin console.

More articles…