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:
|
class Meta:
|
||||||
ordering = ["-date"]
|
ordering = ["-date"]
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def clean(self):
|
||||||
if self.response_deadline is None:
|
if self.response_deadline is None:
|
||||||
self.response_deadline = self.date - timedelta(hours=24)
|
self.response_deadline = self.date - timedelta(hours=24)
|
||||||
return super().save(*args, **kwargs)
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"{self.title} on {self.date}"
|
return f"{self.title} on {self.date}"
|
||||||
|
|
|
@ -41,14 +41,13 @@ class User(AbstractUser):
|
||||||
ordering = ["rank", "username"]
|
ordering = ["rank", "username"]
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
|
if not hasattr(self, "rank"):
|
||||||
|
self.rank = Rank.objects.last()
|
||||||
if hasattr(self, "main") and self.main.user != self:
|
if hasattr(self, "main") and self.main.user != self:
|
||||||
raise ValidationError({"main": "Main character must be owned by user."})
|
raise ValidationError({"main": "Main character must be owned by user."})
|
||||||
|
|
||||||
@transaction.atomic
|
@transaction.atomic
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
if not hasattr(self, "rank"):
|
|
||||||
self.rank = Rank.objects.last()
|
|
||||||
|
|
||||||
if not hasattr(self, "main"):
|
if not hasattr(self, "main"):
|
||||||
self.main = Character.objects.create(
|
self.main = Character.objects.create(
|
||||||
user=None,
|
user=None,
|
||||||
|
|
Loading…
Reference in a new issue