What is the Django equivalence for Flask's UserMixin?

Question:

In Flask there is the flask.ext.login.UserMixin from the flask-login module.

I’ve tried to looked for the Django equivalence and the closest thing to the Flask’s UserMixin is the django.contrib.auth.models.User from
https://docs.djangoproject.com/en/1.9/ref/contrib/auth/

Is that the Django’s equivalence to Flask’s UserMixin? What are the differences?

In PyBossa, using Flask’s UserMixin, they have inherited from the UserMixin to add twitter/facebook oauth, can django.contrib.auth.models.User be inherited and sub-classed to do the same?

Asked By: alvas

||

Answers:

Indeed. It’s a model that stores information about a logged in User. Same thing.

You can either extend the model or replace it entirely.

There are two ways to extend the default User model without substituting your own model. If the changes you need are purely behavioral, and don’t require any change to what is stored in the database, you can create a proxy model based on User. This allows for any of the features offered by proxy models including default ordering, custom managers, or custom model methods.

Extending Model:
https://docs.djangoproject.com/en/1.9/topics/auth/customizing/#extending-the-existing-user-model

Replacing User Model:
https://docs.djangoproject.com/en/1.9/topics/auth/customizing/#substituting-a-custom-user-model

Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.