Updated approach to make it compatible with Django 1.7 (backward-compatible:tested with django-1.7b1, django-1.6.2, django-1.6.1)