Opened 4 years ago

Closed 4 years ago

#25201 closed New feature (fixed)

Allow use_for_related_fields via as_manager()

Reported by: Simon Litchfield Owned by: Anderson Resende
Component: Database layer (models, ORM) Version: 1.8
Severity: Normal Keywords: use_for_related_fields
Cc: Loic Bistuer Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The as_manager() method allows easy creation of chain-able managers. One of the most common use cases for these is with related fields. However, as_manager() doesn't currently allow use_for_related_fields to be specified. This patch proposes it could be set simply by way of an attribute on the QuerySet class, in the same way it currently does for Manager classes.

Change History (8)

comment:1 Changed 4 years ago by Anderson Resende

Owner: changed from nobody to Anderson Resende
Status: newassigned

comment:2 Changed 4 years ago by Tim Graham

Easy pickings: unset
Has patch: unset

ticket:24863#comment:10 might solve this. By the way, if you mean to propose a patch, I don't see it.

comment:3 Changed 4 years ago by Tim Graham

Triage Stage: UnreviewedAccepted

I think the general idea is accepted even if the exact API needs to be worked out.

comment:4 Changed 4 years ago by Tim Graham

Cc: Loic Bistuer added

Loic, can we close this in light of your PR to refactor manager inheritance (and deprecate use_for_related_fields)?

comment:5 Changed 4 years ago by Loic Bistuer

Indeed, but maybe we should let the commit messages close this ticket? Not counting the chickens before they're hatched kinda thing?

comment:6 Changed 4 years ago by Tim Graham

Keywords: use_for_related_fields added

comment:7 Changed 4 years ago by Loic Bistuer

PR6175 deprecates use_for_related_fields.

comment:8 Changed 4 years ago by Loïc Bistuer <loic.bistuer@…>

Resolution: fixed
Status: assignedclosed

In ed0ff91:

Fixed #10506, #13793, #14891, #25201 -- Introduced new APIs to specify models' default and base managers.

This deprecates use_for_related_fields.

Old API:

class CustomManager(models.Model):

use_for_related_fields = True

class Model(models.Model):

custom_manager = CustomManager()

New API:

class Model(models.Model):

custom_manager = CustomManager()

class Meta:

base_manager_name = 'custom_manager'

Refs #20932, #25897.

Thanks Carl Meyer for the guidance throughout this work.
Thanks Tim Graham for writing the docs.

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