Adapted to work with custom user model

I made these changes a while ago and don't exactly remember what's the state of test suite and Django < 1.5 support, but take a look at this to support custom user models.