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:
BooleanField, or an
choiceswhich 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.
Consider as an example this model, which might be found in a project-management or customer-relations application:
ORG_TYPE_CHOICES = ((1, 'Internal'), (2, 'External')) class Organization(models.Model): name = models.CharField(maxlength=200) slug = models.SlugField(prepopulate_from=('name',)) contact_person = …