Support custom user models in Django 1.5+

This adds support for custom user models in Django 1.5+ whilst still maintaing support for older versions.