Brad's Blog

Published: 2012-09-26

Django Models & Mixins for cleaner code

django mixins programming python

I've been using Mixins lately to DRY-ly make certain behavior available to several different Django models. If you're not familiar with mixins, there's a great discussion over on StackOverflow. Here's a simple example to illustrate what I've been doing. In building Work for Pie, we've got a UserProfile model that looks something like this: class UserProfile(models.Model): user = models.OneToOneField(User) tagline = models.CharField(max_length=140) biography = models.TextField() avatar_url = models.URLField(max_length ...