Opened 9 years ago

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


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 by Anderson Resende, 9 years ago

Owner: changed from nobody to Anderson Resende
Status: newassigned

comment:2 by Tim Graham, 9 years ago

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 by Tim Graham, 9 years ago

Triage Stage: UnreviewedAccepted

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

comment:4 by Tim Graham, 8 years ago

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 by Loic Bistuer, 8 years ago

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

comment:6 by Tim Graham, 8 years ago

Keywords: use_for_related_fields added

comment:7 by Loic Bistuer, 8 years ago

PR6175 deprecates use_for_related_fields.

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

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