Skip to content

Commit

Permalink
override using argument
Browse files Browse the repository at this point in the history
  • Loading branch information
dopatraman committed Mar 26, 2019
1 parent 1eea22f commit 59afcf2
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions simple_history/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def __init__(
history_user_id_field=None,
history_user_getter=_history_user_getter,
history_user_setter=_history_user_setter,
using=None,
):
self.user_set_verbose_name = verbose_name
self.user_related_name = user_related_name
Expand All @@ -93,6 +94,7 @@ def __init__(
self.user_id_field = history_user_id_field
self.user_getter = history_user_getter
self.user_setter = history_user_setter
self.using = using

if excluded_fields is None:
excluded_fields = []
Expand Down Expand Up @@ -413,14 +415,14 @@ def post_save(self, instance, created, using=None, **kwargs):
if not created and hasattr(instance, "skip_history_when_saving"):
return
if not kwargs.get("raw", False):
self.create_historical_record(instance, created and "+" or "~", using=(instance.history.db or using))
self.create_historical_record(instance, created and "+" or "~", using=(self.using or using))

def post_delete(self, instance, using=None, **kwargs):
if self.cascade_delete_history:
manager = getattr(instance, self.manager_name)
manager.using(using).all().delete()
else:
self.create_historical_record(instance, "-", using=(instance.history.db or using))
self.create_historical_record(instance, "-", using=(self.using or using))

def create_historical_record(self, instance, history_type, using=None):
history_date = getattr(instance, "_history_date", now())
Expand Down

0 comments on commit 59afcf2

Please sign in to comment.