From 0ac3bda6b701ce4af861f43f8a9940e190e2a74e Mon Sep 17 00:00:00 2001 From: "Casper V. Kristensen" Date: Tue, 19 Nov 2019 04:18:47 +0100 Subject: [PATCH] Move clean logic to clean() instead of save() --- drakul/raids/models.py | 3 +-- drakul/users/models.py | 5 ++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/drakul/raids/models.py b/drakul/raids/models.py index 45c7d93..5869c7e 100755 --- a/drakul/raids/models.py +++ b/drakul/raids/models.py @@ -26,10 +26,9 @@ class Raid(models.Model): class Meta: ordering = ["-date"] - def save(self, *args, **kwargs): + def clean(self): if self.response_deadline is None: self.response_deadline = self.date - timedelta(hours=24) - return super().save(*args, **kwargs) def __str__(self): return f"{self.title} on {self.date}" diff --git a/drakul/users/models.py b/drakul/users/models.py index ae0a5d0..1166d99 100644 --- a/drakul/users/models.py +++ b/drakul/users/models.py @@ -41,14 +41,13 @@ class User(AbstractUser): ordering = ["rank", "username"] def clean(self): + if not hasattr(self, "rank"): + self.rank = Rank.objects.last() if hasattr(self, "main") and self.main.user != self: raise ValidationError({"main": "Main character must be owned by user."}) @transaction.atomic def save(self, *args, **kwargs): - if not hasattr(self, "rank"): - self.rank = Rank.objects.last() - if not hasattr(self, "main"): self.main = Character.objects.create( user=None,