django-planet

James Bennett

Blog Info James Bennett
Blog website Link

Don't use class methods on Django models

Dec. 17, 2023 » James Bennett » [Archived Version]

This is part of a series of posts I’m doing as a sort of Python/Django Advent calendar, offering a small tip or piece of information each day from the first Sunday of Advent through Christmas Eve. See the first post for an introduction. Being methodical about Python Python classes support three basic types of methods: Instance methods, which are what you get by default when writing a def statement inside a class body. These are … Read full entry

Read More

Say what you mean in a regex

Dec. 17, 2023 » James Bennett » [Archived Version]

This is part of a series of posts I’m doing as a sort of Python/Django Advent calendar, offering a small tip or piece of information each day from the first Sunday of Advent through Christmas Eve. See the first post for an introduction. An URL-y warning Suppose you’re writing a blog in Django, and you get to the point where you’re setting up the URLs for the entries. Django has two ways to write … Read full entry

Read More

Python packaging: use the "src"

Dec. 15, 2023 » James Bennett » [Archived Version]

This is part of a series of posts I’m doing as a sort of Python/Django Advent calendar, offering a small tip or piece of information each day from the first Sunday of Advent through Christmas Eve. See the first post for an introduction. A lurking problem Imagine you write a Python library named, say, foo. And you diligently set up the configuration to package it for distribution (which is not that hard; you can … Read full entry

Read More

Database functions in Django

Dec. 15, 2023 » James Bennett » [Archived Version]

This is part of a series of posts I’m doing as a sort of Python/Django Advent calendar, offering a small tip or piece of information each day from the first Sunday of Advent through Christmas Eve. See the first post for an introduction. Functionally a database On top of the basic query syntax we’re all used to, SQL databases tend to have a large number of built-in functions — some of which are standardized, some … Read full entry

Read More

Database views in Django

Dec. 14, 2023 » James Bennett » [Archived Version]

This is part of a series of posts I’m doing as a sort of Python/Django Advent calendar, offering a small tip or piece of information each day from the first Sunday of Advent through Christmas Eve. See the first post for an introduction. A view to a database Most databases support creating and working with views, which, if you’ve never encountered them before, are like a virtual table — instead of being defined by … Read full entry

Read More

Django's three types of model inheritance

Dec. 13, 2023 » James Bennett » [Archived Version]

This is part of a series of posts I’m doing as a sort of Python/Django Advent calendar, offering a small tip or piece of information each day from the first Sunday of Advent through Christmas Eve. See the first post for an introduction. Inheritance and its discontents People can, and do, debate whether inheritance in object-oriented programming languages is a thing that ought to exist. There are even debates about what “inheritance” ought to mean … Read full entry

Read More

Raise the right exceptions

Dec. 12, 2023 » James Bennett » [Archived Version]

This is part of a series of posts I’m doing as a sort of Python/Django Advent calendar, offering a small tip or piece of information each day from the first Sunday of Advent through Christmas Eve. See the first post for an introduction. Let’s have an argument Suppose you write a function like this: def divide(dividend, divisor): """ Divide ``dividend`` by ``divisor`` and return the result. """ return dividend … Read full entry

Read More

Test your documentation

Dec. 10, 2023 » James Bennett » [Archived Version]

This is part of a series of posts I’m doing as a sort of Python/Django Advent calendar, offering a small tip or piece of information each day from the first Sunday of Advent through Christmas Eve. See the first post for an introduction. Consider a docstring Suppose you’re writing a Python function and, as you’re supposed to do, you give it a docstring, and you even provide some examples of how the function is supposed … Read full entry

Read More

Bullets of vaguely silvery hue

Oct. 20, 2023 » James Bennett » [Archived Version]

There is no single development, in either technology or management technique, which by itself promises even a single order-of-magnitude improvement within a decade in productivity, in reliability, in simplicity. If “The Mythical Man-Month” — or at least the popular distillation of it into a single pithy saying — is the most famous thing the late Fred Brooks ever wrote, then “No Silver Bullet”, the essay quoted above, must surely be the most infamous, o…

Read More

Boring Python: code quality

Dec. 19, 2022 » James Bennett » [Archived Version]

This is the second in a series of posts I intend to write about how to build, deploy, and manage Python applications in as boring a way as possible. In the first post in the series I gave a definition of what I mean by “boring”, and it’s worth revisiting: I don’t mean “reliable” or “bug-free” or “no incidents”. While there is some overlap, and some of the things I’ll be recommending can help to reduce … Read full entry

Read More