diff --git a/app/models.py b/app/models.py index 681a433..717a1cf 100644 --- a/app/models.py +++ b/app/models.py @@ -40,6 +40,7 @@ class Drink(models.Model): do_not_count = models.BooleanField(default=False) def delete(self, *args, **kwargs): + # we flag the field as deleted. self.deleted = True super().save() @@ -107,10 +108,9 @@ class Order(models.Model): price_sum = models.DecimalField(max_digits=6, decimal_places=2, default=0, editable=False) content_litres = models.DecimalField(max_digits=6, decimal_places=3, default=0, editable=False) - # TODO: Add more comments on how and why the save & delete functions are implemented - # address this in a refactoring issue. - def save(self, *args, **kwargs): + # saving this may affect other fields + # so we reimplement the save function drink = Drink.objects.get(pk=self.drink.pk) if self._state.adding and drink.available > 0: if not drink.do_not_count: @@ -126,6 +126,7 @@ class Order(models.Model): raise ValidationError("This entry can't be changed.") def delete(self, *args, **kwargs): + # when deleting, we affect other fields as well. self.user.balance += self.price_sum self.user.save() drink = Drink.objects.get(pk=self.drink.pk) diff --git a/scripts/_bootstrap.py b/scripts/_bootstrap.py index 7cdee55..c162c03 100755 --- a/scripts/_bootstrap.py +++ b/scripts/_bootstrap.py @@ -14,7 +14,7 @@ from time import sleep from yaml import safe_load -banner = """ ___ _ _ +banner = r""" ___ _ _ | \ _ _ (_) _ _ | |__ ___ ___ | |) || '_|| || ' \ | / /(_-< |___| |___/ |_| |_||_||_||_\_\/__/