I want to add a convenience/model method to the django.contrib.auth.models.User model. What is the best practice for doing this since, last time I checked, extending the User model was considered bad practice.
I have a separate custom UserProfile model. Should I be using that for all User-related convenience methods?
It depends what you are trying to add to the model. If you want to add more information about the user, then it is generally recommended that you use the
UserProfilemethod: http://docs.djangoproject.com/en/dev/topics/auth/#storing-additional-information-about-usersHowever, if you just want to add custom methods or managers to the
Usermodel, I would say that it’s more logical to use a proxy model, like so:A proxy model will operate on the same database table as the original model, so is ideal for creating custom methods without physically extending the model. Just replace any references to
Userin your views toUserMethods. (And of course you can use this in the admin tool by unregistering theUsermodel and registering your proxy model in its stead.)Any instances of the original
Usermodel that are created will be instantly accessible via theUserMethodsmodel, and vice-versa. More here: http://docs.djangoproject.com/en/dev/topics/db/models/#proxy-models(NB. Proxy models require Django 1.1 and above)