Add additional, model-imposed failsafe for (main) character deletion.
This commit is contained in:
parent
0bf64182f5
commit
41eff3bec2
|
@ -123,5 +123,12 @@ class Character(models.Model):
|
|||
def clean(self):
|
||||
self.name = self.name.capitalize()
|
||||
|
||||
def delete(self, *args, **kwargs):
|
||||
if self.user.main == self:
|
||||
# Sanity check: this is already checked by the profile and admin forms which allow character deletion, but
|
||||
# we check it again to avoid unintentionally cascading the delete to the entire user.
|
||||
raise ValidationError("Can't delete user's main character.")
|
||||
return super().delete(*args, **kwargs)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
|
Loading…
Reference in a new issue