瀏覽代碼

修改同步问题

wxl 1 年之前
父節點
當前提交
46ebd93708
共有 2 個文件被更改,包括 12 次插入3 次删除
  1. 8 2
      dj_cqrs/management/commands/cqrs_sync.py
  2. 4 1
      dj_cqrs/mixins.py

+ 8 - 2
dj_cqrs/management/commands/cqrs_sync.py

@@ -120,7 +120,10 @@ class Command(BaseCommand):
 
     @staticmethod
     def _prepare_qs(model, options):
-        qs = model._default_manager.none()
+        if hasattr(model, 'objects_all'):  # wxl 2023-8-29
+            qs = model.objects_all.none()
+        else:
+            qs = model._default_manager.none()
         if options['filter']:
             try:
                 kwargs = ujson.loads(options['filter'])
@@ -130,7 +133,10 @@ class Command(BaseCommand):
                 raise CommandError('Bad filter kwargs!')
 
             try:
-                qs = model._default_manager.filter(**kwargs).order_by()
+                if hasattr(model, 'objects_all'):  # wxl 2023-8-29
+                    qs = model.objects_all.filter(**kwargs).order_by()
+                else:
+                    qs = model._default_manager.filter(**kwargs).order_by()
             except FieldError as e:
                 raise CommandError('Bad filter kwargs! {0}'.format(str(e)))
 

+ 4 - 1
dj_cqrs/mixins.py

@@ -294,7 +294,10 @@ class RawMasterMixin(Model):
             instance = self
         else:
             db = using if using is not None else self._state.db
-            qs = self.__class__._default_manager.using(db)
+            if hasattr(self.__class__, 'objects_all'):  # wxl 2023-8-29
+                qs = self.__class__.objects_all.using(db)
+            else:
+                qs = self.__class__._default_manager.using(db)
             instance = self.relate_cqrs_serialization(qs).get(pk=self.pk)
 
         data = self._cqrs_serializer_cls(instance).data