Skip to main content


Showing posts from August, 2013

Normalize '__unicode__' accross django models

Don't repeat your self, use monkeypatching - a better default '__unicode__' This latest top-secret project for sure is keeping me busy and time wise leaves little to keep blogging, however it being Friday and all and because you're worth it here is a Django expert tip. Django's default '__unicode__' representation leaves a bit to be desired to say the least. In a nut shell it returns the class name + 'object' for all instances and so requires that all your models have a '__unicode__' defined to have a useful string represenation. Well with a bit of friendly monkeys we can patch it right up as per the code below: from django.db.models.base import Model import logging import hashlib import re from django.conf import settings logger = logging.getLogger(__name__) #----------------------------------------------------------------------------------------------------------------------"Patching 'django.db.models.base.M