Opened 4 years ago

Closed 4 years ago

#16379 closed Bug (invalid)

Override UserManager

Reported by: thibaultj Owned by: nobody
Component: contrib.auth Version: 1.3
Severity: Normal Keywords: auth, user, manager, usermanager
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


In contrib.auth, the User class is affected a custom UserManager manager. I cannot find any clean way to override this manager, or to define a new one.

This is a problem in the following case: I created a middleware to manage acl. So in every request, I need to access request.user.profile.something. I'd like to override the get_query_set() method of the UserManager, to use select_related().

The only possible solution seems to monkey patch user class in a middleware, as suggested here :

Change History (2)

comment:1 Changed 4 years ago by apollo13

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Use to attach to the User class registration and then use manager.contribute_to_class to attach your manager. Even if it doesn't work, I don't think anything should be changed now since app-refactor will provide that afaik.

comment:2 Changed 4 years ago by aaugustin

  • Resolution set to invalid
  • Status changed from new to closed

This is more a usage question than a bug in Django, and apollo13 provided a solution.

Note: See TracTickets for help on using tickets.
Back to Top