1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Prevent duplicate contact assignments

This commit is contained in:
jeremystretch
2021-10-18 16:33:31 -04:00
parent 487d67768b
commit b44a5ea609
2 changed files with 23 additions and 32 deletions

View File

@ -14,24 +14,6 @@ class Migration(migrations.Migration):
]
operations = [
migrations.CreateModel(
name='Contact',
fields=[
('created', models.DateField(auto_now_add=True, null=True)),
('last_updated', models.DateTimeField(auto_now=True, null=True)),
('custom_field_data', models.JSONField(blank=True, default=dict, encoder=django.core.serializers.json.DjangoJSONEncoder)),
('id', models.BigAutoField(primary_key=True, serialize=False)),
('name', models.CharField(max_length=100)),
('title', models.CharField(blank=True, max_length=100)),
('phone', models.CharField(blank=True, max_length=50)),
('email', models.EmailField(blank=True, max_length=254)),
('address', models.CharField(blank=True, max_length=200)),
('comments', models.TextField(blank=True)),
],
options={
'ordering': ['name'],
},
),
migrations.CreateModel(
name='ContactRole',
fields=[
@ -68,6 +50,27 @@ class Migration(migrations.Migration):
'unique_together': {('parent', 'name')},
},
),
migrations.CreateModel(
name='Contact',
fields=[
('created', models.DateField(auto_now_add=True, null=True)),
('last_updated', models.DateTimeField(auto_now=True, null=True)),
('custom_field_data', models.JSONField(blank=True, default=dict, encoder=django.core.serializers.json.DjangoJSONEncoder)),
('id', models.BigAutoField(primary_key=True, serialize=False)),
('name', models.CharField(max_length=100)),
('title', models.CharField(blank=True, max_length=100)),
('phone', models.CharField(blank=True, max_length=50)),
('email', models.EmailField(blank=True, max_length=254)),
('address', models.CharField(blank=True, max_length=200)),
('comments', models.TextField(blank=True)),
('group', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='contacts', to='tenancy.contactgroup')),
('tags', taggit.managers.TaggableManager(through='extras.TaggedItem', to='extras.Tag')),
],
options={
'ordering': ['name'],
'unique_together': {('group', 'name')},
},
),
migrations.CreateModel(
name='ContactAssignment',
fields=[
@ -82,20 +85,7 @@ class Migration(migrations.Migration):
],
options={
'ordering': ('priority', 'contact'),
'unique_together': {('content_type', 'object_id', 'contact', 'role', 'priority')},
},
),
migrations.AddField(
model_name='contact',
name='group',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='contacts', to='tenancy.contactgroup'),
),
migrations.AddField(
model_name='contact',
name='tags',
field=taggit.managers.TaggableManager(through='extras.TaggedItem', to='extras.Tag'),
),
migrations.AlterUniqueTogether(
name='contact',
unique_together={('group', 'name')},
),
]

View File

@ -259,6 +259,7 @@ class ContactAssignment(ChangeLoggedModel):
class Meta:
ordering = ('priority', 'contact')
unique_together = ('content_type', 'object_id', 'contact', 'role', 'priority')
def __str__(self):
return f"{self.contact} ({self.get_priority_display()})" if self.priority else self.name