mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-24 08:25:17 -06:00
10408 add error message if already exists
This commit is contained in:
parent
96784640e3
commit
b833831bda
@ -1,5 +1,6 @@
|
|||||||
from django.contrib.contenttypes.fields import GenericForeignKey
|
from django.contrib.contenttypes.fields import GenericForeignKey
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
|
from django.core.exceptions import ValidationError
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from mptt.models import TreeForeignKey
|
from mptt.models import TreeForeignKey
|
||||||
@ -119,7 +120,7 @@ class Contact(NetBoxModel):
|
|||||||
class Meta:
|
class Meta:
|
||||||
ordering = ['name']
|
ordering = ['name']
|
||||||
unique_together = (
|
unique_together = (
|
||||||
('group', 'name')
|
('group', 'name'),
|
||||||
)
|
)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
@ -168,3 +169,11 @@ class ContactAssignment(WebhooksMixin, ChangeLoggedModel):
|
|||||||
|
|
||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
return reverse('tenancy:contact', args=[self.contact.pk])
|
return reverse('tenancy:contact', args=[self.contact.pk])
|
||||||
|
|
||||||
|
def validate_unique(self, exclude=None):
|
||||||
|
if ContactAssignment.objects.exclude(pk=self.pk).filter(content_type=self.content_type, object_id=self.object_id, role=self.role, priority=self.priority).exists():
|
||||||
|
raise ValidationError({
|
||||||
|
'role': f'A contact assignment for this already exists.'
|
||||||
|
})
|
||||||
|
|
||||||
|
super().validate_unique(exclude=exclude)
|
||||||
|
Loading…
Reference in New Issue
Block a user