Opened 13 years ago
Closed 13 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 |
Description
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 :
http://stackoverflow.com/questions/6518280/override-usermanager-in-django
Change History (2)
comment:1 by , 13 years ago
comment:2 by , 13 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
This is more a usage question than a bug in Django, and apollo13 provided a solution.
Use https://docs.djangoproject.com/en/dev/ref/signals/#class-prepared 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.