mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Add uniqueness check for PartParameterTemplate name field
- Case insensitive
This commit is contained in:
parent
a228b38e5d
commit
db834802e3
@ -1050,6 +1050,21 @@ class PartParameterTemplate(models.Model):
|
||||
s += " ({units})".format(units=self.units)
|
||||
return s
|
||||
|
||||
def validate_unique(self, exclude=None):
|
||||
""" Ensure that PartParameterTemplates cannot be created with the same name.
|
||||
This test should be case-insensitive (which the unique caveat does not cover).
|
||||
"""
|
||||
|
||||
super().validate_unique(exclude)
|
||||
|
||||
try:
|
||||
others = PartParameterTemplate.objects.exclude(id=self.id).filter(name__iexact=self.name)
|
||||
|
||||
if others.exists():
|
||||
msg = _("Parameter template name must be unique")
|
||||
raise ValidationError({"name": msg})
|
||||
except PartParameterTemplate.DoesNotExist:
|
||||
pass
|
||||
|
||||
name = models.CharField(max_length=100, help_text='Parameter Name')
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user