diff --git a/netbox/tenancy/migrations/0003_contacts.py b/netbox/tenancy/migrations/0003_contacts.py index 6f77810f3..35e568ab1 100644 --- a/netbox/tenancy/migrations/0003_contacts.py +++ b/netbox/tenancy/migrations/0003_contacts.py @@ -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')}, - ), ] diff --git a/netbox/tenancy/models.py b/netbox/tenancy/models.py index 20708f74a..35c10938b 100644 --- a/netbox/tenancy/models.py +++ b/netbox/tenancy/models.py @@ -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