Move clean logic to clean() instead of save()
This commit is contained in:
parent
9af691f8ca
commit
0ac3bda6b7
|
@ -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}"
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue