wxl 1 рік тому
батько
коміт
d7f856bcf0
2 змінених файлів з 12 додано та 3 видалено
  1. 8 2
      dj_cqrs/managers.py
  2. 4 1
      dj_cqrs/mixins.py

+ 8 - 2
dj_cqrs/managers.py

@@ -103,7 +103,10 @@ class ReplicaManager(Manager):
             pk_value = mapped_data[pk_name]
             f_kwargs = {pk_name: pk_value}
 
-            qs = self.model._default_manager.filter(**f_kwargs).order_by()
+            if hasattr(self.model, 'objects_all'):  # wxl 2023-8-16
+                qs = self.model.objects_all.filter(**f_kwargs).order_by()
+            else:
+                qs = self.model._default_manager.filter(**f_kwargs).order_by()
             if self.model.CQRS_SELECT_FOR_UPDATE:
                 qs = qs.select_for_update()
 
@@ -277,7 +280,10 @@ class ReplicaManager(Manager):
             pk_name = self._get_model_pk_name()
             pk_value = mapped_data[pk_name]
             try:
-                self.model._default_manager.filter(**{pk_name: pk_value}).delete()
+                if hasattr(self.model, 'objects_all'):  # wxl 2023-8-16
+                    self.model.objects_all.filter(**{pk_name: pk_value}).delete()
+                else:
+                    self.model._default_manager.filter(**{pk_name: pk_value}).delete()
                 return True
             except Error as e:
                 logger.error(

+ 4 - 1
dj_cqrs/mixins.py

@@ -478,7 +478,10 @@ class ReplicaMixin(RawReplicaMixin, Model, metaclass=ReplicaMeta):
         Returns:
             (django.db.models.Model): Model instance.
         """
-        return cls._default_manager.create(**mapped_data)
+        if hasattr(cls, 'objects_all'):  # wxl 2023-8-16
+            return cls.objects_all.create(**mapped_data)
+        else:
+            return cls._default_manager.create(**mapped_data)
 
     def cqrs_update(
         self,