Django get current user globally in the project

Sometimes, you will need to get the current authenticated user in models, or other parts of your app.

To achieve this, you must create this middleware and add it to MIDDLEWARE_CLASSES in project settings:

Usage example: