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:
@ -14,24 +14,6 @@ class Migration(migrations.Migration):
|
|||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
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(
|
migrations.CreateModel(
|
||||||
name='ContactRole',
|
name='ContactRole',
|
||||||
fields=[
|
fields=[
|
||||||
@ -68,6 +50,27 @@ class Migration(migrations.Migration):
|
|||||||
'unique_together': {('parent', 'name')},
|
'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(
|
migrations.CreateModel(
|
||||||
name='ContactAssignment',
|
name='ContactAssignment',
|
||||||
fields=[
|
fields=[
|
||||||
@ -82,20 +85,7 @@ class Migration(migrations.Migration):
|
|||||||
],
|
],
|
||||||
options={
|
options={
|
||||||
'ordering': ('priority', 'contact'),
|
'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')},
|
|
||||||
),
|
|
||||||
]
|
]
|
||||||
|
@ -259,6 +259,7 @@ class ContactAssignment(ChangeLoggedModel):
|
|||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ('priority', 'contact')
|
ordering = ('priority', 'contact')
|
||||||
|
unique_together = ('content_type', 'object_id', 'contact', 'role', 'priority')
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"{self.contact} ({self.get_priority_display()})" if self.priority else self.name
|
return f"{self.contact} ({self.get_priority_display()})" if self.priority else self.name
|
||||||
|
Reference in New Issue
Block a user