django-bulk-hooks 0.1.182__py3-none-any.whl → 0.1.184__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of django-bulk-hooks might be problematic. Click here for more details.
- django_bulk_hooks/queryset.py +38 -26
- {django_bulk_hooks-0.1.182.dist-info → django_bulk_hooks-0.1.184.dist-info}/METADATA +1 -1
- {django_bulk_hooks-0.1.182.dist-info → django_bulk_hooks-0.1.184.dist-info}/RECORD +5 -5
- {django_bulk_hooks-0.1.182.dist-info → django_bulk_hooks-0.1.184.dist-info}/LICENSE +0 -0
- {django_bulk_hooks-0.1.182.dist-info → django_bulk_hooks-0.1.184.dist-info}/WHEEL +0 -0
django_bulk_hooks/queryset.py
CHANGED
|
@@ -14,6 +14,7 @@ from django_bulk_hooks.constants import (
|
|
|
14
14
|
VALIDATE_UPDATE,
|
|
15
15
|
)
|
|
16
16
|
from django_bulk_hooks.context import HookContext
|
|
17
|
+
from django.db.models import When, Value, Case
|
|
17
18
|
|
|
18
19
|
|
|
19
20
|
class HookQuerySet(models.QuerySet):
|
|
@@ -554,35 +555,46 @@ class HookQuerySet(models.QuerySet):
|
|
|
554
555
|
if not model_fields:
|
|
555
556
|
continue
|
|
556
557
|
|
|
557
|
-
#
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
558
|
+
# For MTI, we need to handle parent links correctly
|
|
559
|
+
# The root model (first in chain) has its own PK
|
|
560
|
+
# Child models use the parent link to reference the root PK
|
|
561
|
+
if model == inheritance_chain[0]:
|
|
562
|
+
# Root model - use primary keys directly
|
|
563
|
+
pks = [obj.pk for obj in objs]
|
|
564
|
+
filter_field = 'pk'
|
|
565
|
+
else:
|
|
566
|
+
# Child model - use parent link field
|
|
567
|
+
parent_link = None
|
|
568
|
+
for parent_model in inheritance_chain:
|
|
569
|
+
if parent_model in model._meta.parents:
|
|
570
|
+
parent_link = model._meta.parents[parent_model]
|
|
571
|
+
break
|
|
562
572
|
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
setattr(temp_obj, pk_field.attname, pk_value)
|
|
573
|
+
if parent_link is None:
|
|
574
|
+
# This shouldn't happen in proper MTI, but handle gracefully
|
|
575
|
+
continue
|
|
567
576
|
|
|
568
|
-
#
|
|
569
|
-
|
|
577
|
+
# Get the parent link values (these should be the same as the root PKs)
|
|
578
|
+
pks = [getattr(obj, parent_link.attname) for obj in objs]
|
|
579
|
+
filter_field = parent_link.attname
|
|
580
|
+
|
|
581
|
+
if pks:
|
|
582
|
+
base_qs = model._base_manager.using(self.db)
|
|
570
583
|
|
|
571
|
-
#
|
|
572
|
-
|
|
573
|
-
temp_obj._state.db = self.db
|
|
574
|
-
|
|
575
|
-
# Copy only the fields for this model
|
|
584
|
+
# Build CASE statements for each field
|
|
585
|
+
case_statements = {}
|
|
576
586
|
for field_name in model_fields:
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
+
field = model._meta.get_field(field_name)
|
|
588
|
+
when_statements = []
|
|
589
|
+
|
|
590
|
+
for pk, obj in zip(pks, objs):
|
|
591
|
+
value = getattr(obj, field_name)
|
|
592
|
+
when_statements.append(When(**{filter_field: pk}, then=Value(value, output_field=field)))
|
|
593
|
+
|
|
594
|
+
case_statements[field_name] = Case(*when_statements, output_field=field)
|
|
595
|
+
|
|
596
|
+
# Execute the update using the appropriate filter field
|
|
597
|
+
updated_count = base_qs.filter(**{f"{filter_field}__in": pks}).update(**case_statements)
|
|
598
|
+
total_updated += updated_count
|
|
587
599
|
|
|
588
600
|
return total_updated
|
|
@@ -9,9 +9,9 @@ django_bulk_hooks/handler.py,sha256=xZt8iNdYF-ACz-MnKMY0co6scWINU5V5wC1lyDn844k,
|
|
|
9
9
|
django_bulk_hooks/manager.py,sha256=KLEjpQRt4WlzgBAf_X3XOAPUQM8Jmc1fIt8yr62FPQc,3044
|
|
10
10
|
django_bulk_hooks/models.py,sha256=7fnx5xd4HWXfLVlFhhiRzR92JRWFEuxgk6aSWLEsyJg,3996
|
|
11
11
|
django_bulk_hooks/priority.py,sha256=HG_2D35nga68lBCZmSXTcplXrjFoRgZFRDOy4ROKonY,376
|
|
12
|
-
django_bulk_hooks/queryset.py,sha256=
|
|
12
|
+
django_bulk_hooks/queryset.py,sha256=gQvwa506wYi206B13I-lwkZi5Ua9nWcKctwCCgLGuaQ,25614
|
|
13
13
|
django_bulk_hooks/registry.py,sha256=-mQBizJ06nz_tajZBinViKx_uP2Tbc1tIpTEMv7lwKA,705
|
|
14
|
-
django_bulk_hooks-0.1.
|
|
15
|
-
django_bulk_hooks-0.1.
|
|
16
|
-
django_bulk_hooks-0.1.
|
|
17
|
-
django_bulk_hooks-0.1.
|
|
14
|
+
django_bulk_hooks-0.1.184.dist-info/LICENSE,sha256=dguKIcbDGeZD-vXWdLyErPUALYOvtX_fO4Zjhq481uk,1088
|
|
15
|
+
django_bulk_hooks-0.1.184.dist-info/METADATA,sha256=zj7hawgW0Z19ZUhnTcTMcx-pMXy_PvepfzUdstynZjU,6951
|
|
16
|
+
django_bulk_hooks-0.1.184.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
|
17
|
+
django_bulk_hooks-0.1.184.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|