Code

Opened 3 years ago

Closed 3 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

Attachments (0)

Change History (2)

comment:1 Changed 3 years ago by apollo13

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

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.

comment:2 Changed 3 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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.