I’ve always disliked having to write __repr__ methods for my classes. It isn’t hard, it is just tedious. In Django, it is especially important to make them, since the admin pages use that method when listing objects from the data model.
However, since Python allows classes to have multiple inheritance, I have long since made a helper “Mixin” class to remove most of the pain from writing my __repr__ methods. If you haven’t heard the term, a “Mixin” is a class which adds functionality to classes which inherit from it. The philosophy is that it shouldn’t change base functionality, thus avoiding many of the problems with multiple inheritance.
Philosophy aside, mixins can be extremely useful, and I love this one. [Read more...]
I’ve been living a split life for six months now.
Now that I am doing professional web layouts for clients, I find myself appreciating the quick, easy, and well-documented
Recent Comments