mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
[1.5.X] Fixed #19384 -- Documented the behavior of custom managers on abstract models.
This documents the behavior introduced bycc337a74, which is BACKWARDS INCOMPATIBLE for any attempt to invoke a method on a manager using the abstract class as the calling class (e.g., AbstractBase.objects.do_something()) Thanks to mhsparks for the report. Backport of1b646e656efrom master.
This commit is contained in:
@@ -274,6 +274,21 @@ it into the inheritance hierarchy *after* the defaults::
|
||||
# Default manager is CustomManager, but OtherManager is
|
||||
# also available via the "extra_manager" attribute.
|
||||
|
||||
Note that while you can *define* a custom manager on the abstract model, you
|
||||
can't *invoke* any methods using the abstract model. That is::
|
||||
|
||||
ClassA.objects.do_something()
|
||||
|
||||
is legal, but::
|
||||
|
||||
AbstractBase.objects.do_something()
|
||||
|
||||
will raise an exception. This is because managers are intended to encapsulate
|
||||
logic for managing collections of objects. Since you can't have a collection of
|
||||
abstract objects, it doesn't make sense to be managing them. If you have
|
||||
functionality that applies to the abstract model, you should put that functionality
|
||||
in a ``staticmethod`` or ``classmethod`` on the abstract model.
|
||||
|
||||
Implementation concerns
|
||||
-----------------------
|
||||
|
||||
|
||||
Reference in New Issue
Block a user