Skip to content

Commit

Permalink
Rename monkeypatch methods objects parameter to objs to match Django
Browse files Browse the repository at this point in the history
  • Loading branch information
niallcm authored and awmath committed Jan 22, 2024
1 parent fdfcd20 commit 7976550
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions bulk_signals/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,39 +19,39 @@ def ready(self):

base_bulk_create = QuerySet.bulk_create

def bulk_create(queryset, objects, **kwargs):
def bulk_create(queryset, objs, **kwargs):
if skip_signal(kwargs):
return base_bulk_create(queryset, objects, **kwargs)
return base_bulk_create(queryset, objs, **kwargs)
# get model label from queryset
model = apps.get_model(queryset.model._meta.label)

signals.pre_bulk_create.send(sender=model, objects=objects, **kwargs)
created_objects = base_bulk_create(queryset, objects, **kwargs)
signals.post_bulk_create.send(sender=model, objects=objects, **kwargs)
signals.pre_bulk_create.send(sender=model, objects=objs, **kwargs)
created_objects = base_bulk_create(queryset, objs, **kwargs)
signals.post_bulk_create.send(sender=model, objects=objs, **kwargs)

return created_objects

QuerySet.bulk_create = bulk_create

base_bulk_update = QuerySet.bulk_update

def bulk_update(queryset, objects, fields, **kwargs):
def bulk_update(queryset, objs, fields, **kwargs):
# add a queryset hint so update signals won't be
# triggerd for bulk_update
queryset._hints["is_bulk_update"] = True

# check if the signals should be skipped
if skip_signal(kwargs):
return base_bulk_update(queryset, objects, fields, **kwargs)
return base_bulk_update(queryset, objs, fields, **kwargs)

model = apps.get_model(queryset.model._meta.label)

signals.pre_bulk_update.send(
sender=model, objects=objects, fields=fields, **kwargs
sender=model, objects=objs, fields=fields, **kwargs
)
return_value = base_bulk_update(queryset, objects, fields, **kwargs)
return_value = base_bulk_update(queryset, objs, fields, **kwargs)
signals.post_bulk_update.send(
sender=model, objects=objects, fields=fields, **kwargs
sender=model, objects=objs, fields=fields, **kwargs
)

return return_value
Expand Down

0 comments on commit 7976550

Please sign in to comment.