24
24
from plain .models .expressions import RawSQL , Value
25
25
from plain .models .fields import NOT_PROVIDED
26
26
from plain .models .fields .reverse_related import ForeignObjectRel
27
- from plain .models .manager import BaseManager , Manager
28
27
from plain .models .options import Options
29
28
from plain .models .query import F , Q
30
29
from plain .packages import packages_registry
@@ -75,7 +74,7 @@ def __new__(cls, name, bases, attrs, **kwargs):
75
74
new_class ._add_exceptions ()
76
75
77
76
# Now go back over all the attrs on this class see if they have a contribute_to_class() method.
78
- # Attributes with contribute_to_class are fields, meta options, and managers .
77
+ # Attributes with contribute_to_class are fields and meta options.
79
78
for attr_name , attr_value in inspect .getmembers (new_class ):
80
79
if attr_name .startswith ("_" ):
81
80
continue
@@ -154,13 +153,6 @@ def _prepare(cls):
154
153
opts = cls ._meta
155
154
opts ._prepare (cls )
156
155
157
- # Validate that 'objects' is either None or a Manager
158
- if cls .objects is not None and not isinstance (cls .objects , BaseManager ):
159
- raise TypeError (
160
- f"Model { cls .__name__ } attribute 'objects' must be either None "
161
- f"or a Manager instance, got { type (cls .objects ).__name__ } "
162
- )
163
-
164
156
# Give the class a docstring -- its definition.
165
157
if cls .__doc__ is None :
166
158
cls .__doc__ = "{}({})" .format (
@@ -176,12 +168,8 @@ def _prepare(cls):
176
168
index .set_name_with_model (cls )
177
169
178
170
@property
179
- def _base_manager (cls ):
180
- return cls ._meta .base_manager
181
-
182
- @property
183
- def _default_manager (cls ):
184
- return cls ._meta .default_manager
171
+ def objects (cls ):
172
+ return cls ._meta .manager
185
173
186
174
187
175
class ModelStateFieldsCacheDescriptor :
@@ -204,7 +192,6 @@ class ModelState:
204
192
205
193
206
194
class Model (metaclass = ModelBase ):
207
- objects = Manager ()
208
195
DoesNotExist : type [ObjectDoesNotExist ]
209
196
MultipleObjectsReturned : type [MultipleObjectsReturned ]
210
197
@@ -435,7 +422,9 @@ def refresh_from_db(self, fields=None):
435
422
"are not allowed in fields."
436
423
)
437
424
438
- db_instance_qs = self .__class__ ._base_manager .get_queryset ().filter (id = self .id )
425
+ db_instance_qs = self .__class__ ._meta .base_manager .get_queryset ().filter (
426
+ id = self .id
427
+ )
439
428
440
429
# Use provided fields, if not set then reload all non-deferred fields.
441
430
deferred_fields = self .get_deferred_fields ()
@@ -618,7 +607,7 @@ def _save_table(
618
607
force_insert = True
619
608
# If possible, try an UPDATE. If that doesn't update anything, do an INSERT.
620
609
if id_set and not force_insert :
621
- base_qs = cls . _base_manager
610
+ base_qs = meta . base_manager
622
611
values = [
623
612
(
624
613
f ,
@@ -642,7 +631,7 @@ def _save_table(
642
631
fields = [f for f in fields if f is not id_field ]
643
632
644
633
returning_fields = meta .db_returning_fields
645
- results = self ._do_insert (cls . _base_manager , fields , returning_fields , raw )
634
+ results = self ._do_insert (meta . base_manager , fields , returning_fields , raw )
646
635
if results :
647
636
for value , field in zip (results [0 ], returning_fields ):
648
637
setattr (self , field .attname , value )
@@ -739,7 +728,7 @@ def _get_next_or_previous_by_FIELD(self, field, is_next, **kwargs):
739
728
q = Q .create ([(field .name , param ), (f"id__{ op } " , self .id )], connector = Q .AND )
740
729
q = Q .create ([q , (f"{ field .name } __{ op } " , param )], connector = Q .OR )
741
730
qs = (
742
- self .__class__ ._default_manager .filter (** kwargs )
731
+ self .__class__ .objects .filter (** kwargs )
743
732
.filter (q )
744
733
.order_by (f"{ order } { field .name } " , f"{ order } id" )
745
734
)
@@ -837,7 +826,7 @@ def _perform_unique_checks(self, unique_checks):
837
826
if len (unique_check ) != len (lookup_kwargs ):
838
827
continue
839
828
840
- qs = model_class ._default_manager .filter (** lookup_kwargs )
829
+ qs = model_class .objects .filter (** lookup_kwargs )
841
830
842
831
# Exclude the current object from the query if we are editing an
843
832
# instance (as opposed to creating a new one)
@@ -1044,7 +1033,6 @@ def _check_db_table_comment(cls, database):
1044
1033
)
1045
1034
return errors
1046
1035
1047
-
1048
1036
@classmethod
1049
1037
def _check_fields (cls , ** kwargs ):
1050
1038
"""Perform all field checks."""
0 commit comments