From d6f00e099903e44e41464b3ed13acd61e47c723e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20H=C3=A4ttasch?= <benjamin.haettasch@fachschaft.informatik.tu-darmstadt.de> Date: Fri, 29 Jan 2021 17:11:44 +0100 Subject: [PATCH] Do not track changes of AK interest counter This fixes #97 Exclude interest_counter from AK history Prevent saving of history record when increasing interest counter Run the following action after applying the change/migration to remove existing duplicate history records (the ones without changes to tracked fields, hence caused by either saving without changing any field or especially the ones created due to changes of the now ignored interest_counter): python manage.py clean_duplicate_history AKModel.ak --- .../0044_ak_history_remove_interest_counter.py | 17 +++++++++++++++++ AKModel/models.py | 4 +++- 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 AKModel/migrations/0044_ak_history_remove_interest_counter.py diff --git a/AKModel/migrations/0044_ak_history_remove_interest_counter.py b/AKModel/migrations/0044_ak_history_remove_interest_counter.py new file mode 100644 index 00000000..203a9863 --- /dev/null +++ b/AKModel/migrations/0044_ak_history_remove_interest_counter.py @@ -0,0 +1,17 @@ +# Generated by Django 3.1.5 on 2021-01-29 15:44 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('AKModel', '0043_akslot_fixed_improve_verbose_name'), + ] + + operations = [ + migrations.RemoveField( + model_name='historicalak', + name='interest_counter', + ), + ] diff --git a/AKModel/models.py b/AKModel/models.py index e614ea0b..9ab9fa3f 100644 --- a/AKModel/models.py +++ b/AKModel/models.py @@ -233,7 +233,7 @@ class AK(models.Model): event = models.ForeignKey(to=Event, on_delete=models.CASCADE, verbose_name=_('Event'), help_text=_('Associated event')) - history = HistoricalRecords() + history = HistoricalRecords(excluded_fields=['interest_counter']) class Meta: verbose_name = _('AK') @@ -272,7 +272,9 @@ class AK(models.Model): def increment_interest(self): self.interest_counter += 1 + self.skip_history_when_saving = True self.save() + del self.skip_history_when_saving @property def availabilities(self): -- GitLab