Implement clean methode for Note
This commit is contained in:
parent
32a37eae29
commit
fb8e6cafef
2 changed files with 67 additions and 36 deletions
|
|
@ -51,7 +51,7 @@ class Note(PolymorphicModel):
|
|||
"""
|
||||
:return: Pretty name of this note
|
||||
"""
|
||||
return 'Not implemented'
|
||||
return str(self)
|
||||
|
||||
pretty.short_description = _('Note')
|
||||
|
||||
|
|
@ -63,7 +63,7 @@ class Note(PolymorphicModel):
|
|||
if aliases.exists():
|
||||
# Alias exists, so check if it is linked to this note
|
||||
if aliases.first().note != self:
|
||||
raise ValidationError
|
||||
raise ValidationError(_('This alias is already taken.'))
|
||||
|
||||
# Save note
|
||||
super().save(*args, **kwargs)
|
||||
|
|
@ -77,6 +77,20 @@ class Note(PolymorphicModel):
|
|||
a.note = self
|
||||
a.save(force_insert=True)
|
||||
|
||||
def clean(self, *args, **kwargs):
|
||||
"""
|
||||
Verify alias (simulate save)
|
||||
"""
|
||||
aliases = Alias.objects.filter(name=str(self))
|
||||
if aliases.exists():
|
||||
# Alias exists, so check if it is linked to this note
|
||||
if aliases.first().note != self:
|
||||
raise ValidationError(_('This alias is already taken.'))
|
||||
else:
|
||||
# Alias does not exist yet, so check if it can exist
|
||||
a = Alias(name=str(self))
|
||||
a.clean()
|
||||
|
||||
|
||||
class NoteUser(Note):
|
||||
"""
|
||||
|
|
@ -144,9 +158,6 @@ class NoteSpecial(Note):
|
|||
def __str__(self):
|
||||
return self.special_type
|
||||
|
||||
def pretty(self):
|
||||
return self.special_type
|
||||
|
||||
|
||||
class Alias(models.Model):
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue