Add unique constraint to address

This commit is contained in:
Nathan Chapman 2023-01-24 17:24:24 -07:00
parent b806160e9d
commit c7f256c5bc
2 changed files with 34 additions and 0 deletions

View File

@ -0,0 +1,17 @@
# Generated by Django 4.1.5 on 2023-01-25 00:17
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('accounts', '0001_initial'),
]
operations = [
migrations.AddConstraint(
model_name='address',
constraint=models.UniqueConstraint(fields=('first_name', 'last_name', 'street_address_1', 'street_address_2', 'city', 'state', 'postal_code'), name='accounts_address_all_key', violation_error_message='Duplicate: Address already exists.'),
),
]

View File

@ -46,6 +46,23 @@ class Address(models.Model):
yield ('postal_code', self.postal_code),
yield ('country_code', 'US')
class Meta:
constraints = [
models.UniqueConstraint(
name='accounts_address_all_key',
fields=[
'first_name',
'last_name',
'street_address_1',
'street_address_2',
'city',
'state',
'postal_code'
],
violation_error_message='Duplicate: Address already exists.'
)
]
class User(AbstractUser):
addresses = models.ManyToManyField(