Entries published on August 18, 2006
I’m going to predict this now
Assuming they’re both still on TV in 2008, Jon Stewart and Stephen Colbert will both run for President. In different parties.
Django tips: using properties on models and managers
While working on a little side project this week, I ran into a couple of very common use cases that often result in a lot of extra typing:
-
Defining a
BooleanField
, or anIntegerField
orCharField
withchoices
which will, logically, break up instances of the model into certain groups which need to be accessed often. - Repeatedly wanting to calculate a value based on the values of several fields of a model.
Let’s look at how to handle these common cases, while reducing the extra typing and making them behave in an extremely intuitive fashion.
The set-up
Consider as an example this model, which …