Tweak uniqueness constraints

This commit is contained in:
jeremystretch 2021-10-18 15:41:29 -04:00
parent faf1e6a43d
commit f485a47b48
2 changed files with 15 additions and 8 deletions

View File

@ -1,5 +1,3 @@
# Generated by Django 3.2.8 on 2021-10-18 16:12
import django.core.serializers.json
from django.db import migrations, models
import django.db.models.deletion
@ -56,8 +54,8 @@ class Migration(migrations.Migration):
('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, unique=True)),
('slug', models.SlugField(max_length=100, unique=True)),
('name', models.CharField(max_length=100)),
('slug', models.SlugField(max_length=100)),
('description', models.CharField(blank=True, max_length=200)),
('lft', models.PositiveIntegerField(editable=False)),
('rght', models.PositiveIntegerField(editable=False)),
@ -67,6 +65,7 @@ class Migration(migrations.Migration):
],
options={
'ordering': ['name'],
'unique_together': {('parent', 'name')},
},
),
migrations.CreateModel(
@ -95,4 +94,8 @@ class Migration(migrations.Migration):
name='tags',
field=taggit.managers.TaggableManager(through='extras.TaggedItem', to='extras.Tag'),
),
migrations.AlterUniqueTogether(
name='contact',
unique_together={('group', 'name')},
),
]

View File

@ -117,12 +117,10 @@ class ContactGroup(NestedGroupModel):
An arbitrary collection of Contacts.
"""
name = models.CharField(
max_length=100,
unique=True
max_length=100
)
slug = models.SlugField(
max_length=100,
unique=True
max_length=100
)
parent = TreeForeignKey(
to='self',
@ -139,6 +137,9 @@ class ContactGroup(NestedGroupModel):
class Meta:
ordering = ['name']
unique_together = (
('parent', 'name')
)
def get_absolute_url(self):
return reverse('tenancy:contactgroup', args=[self.pk])
@ -216,6 +217,9 @@ class Contact(PrimaryModel):
class Meta:
ordering = ['name']
unique_together = (
('group', 'name')
)
def __str__(self):
return self.name