mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Added UniqueConstraint on name/email pair, renamed migration file
This commit is contained in:
parent
7bc925d016
commit
5793839a01
@ -24,16 +24,15 @@ class Migration(migrations.Migration):
|
|||||||
),
|
),
|
||||||
# Convert empty email string to NULL
|
# Convert empty email string to NULL
|
||||||
migrations.RunPython(make_empty_email_field_null),
|
migrations.RunPython(make_empty_email_field_null),
|
||||||
# Make email field unique
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='company',
|
|
||||||
name='email',
|
|
||||||
field=models.EmailField(blank=True, help_text='Contact email address', max_length=254, null=True, unique=True, verbose_name='Email'),
|
|
||||||
),
|
|
||||||
# Remove unique constraint on name field
|
# Remove unique constraint on name field
|
||||||
migrations.AlterField(
|
migrations.AlterField(
|
||||||
model_name='company',
|
model_name='company',
|
||||||
name='name',
|
name='name',
|
||||||
field=models.CharField(help_text='Company name', max_length=100, verbose_name='Company name'),
|
field=models.CharField(help_text='Company name', max_length=100, verbose_name='Company name'),
|
||||||
),
|
),
|
||||||
|
# Add unique constraint on name/email pair
|
||||||
|
migrations.AddConstraint(
|
||||||
|
model_name='company',
|
||||||
|
constraint=models.UniqueConstraint(fields=('name', 'email'), name='unique_name_email_pair'),
|
||||||
|
),
|
||||||
]
|
]
|
@ -12,7 +12,7 @@ import math
|
|||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from django.core.validators import MinValueValidator
|
from django.core.validators import MinValueValidator
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.db.models import Sum, Q
|
from django.db.models import Sum, Q, UniqueConstraint
|
||||||
|
|
||||||
from django.apps import apps
|
from django.apps import apps
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
@ -81,6 +81,9 @@ class Company(models.Model):
|
|||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ['name', ]
|
ordering = ['name', ]
|
||||||
|
constraints = [
|
||||||
|
UniqueConstraint(fields=['name', 'email'], name='unique_name_email_pair')
|
||||||
|
]
|
||||||
|
|
||||||
name = models.CharField(max_length=100, blank=False,
|
name = models.CharField(max_length=100, blank=False,
|
||||||
help_text=_('Company name'),
|
help_text=_('Company name'),
|
||||||
@ -98,7 +101,7 @@ class Company(models.Model):
|
|||||||
verbose_name=_('Phone number'),
|
verbose_name=_('Phone number'),
|
||||||
blank=True, help_text=_('Contact phone number'))
|
blank=True, help_text=_('Contact phone number'))
|
||||||
|
|
||||||
email = models.EmailField(blank=True, null=True, unique=True,
|
email = models.EmailField(blank=True, null=True,
|
||||||
verbose_name=_('Email'), help_text=_('Contact email address'))
|
verbose_name=_('Email'), help_text=_('Contact email address'))
|
||||||
|
|
||||||
contact = models.CharField(max_length=100,
|
contact = models.CharField(max_length=100,
|
||||||
|
Loading…
Reference in New Issue
Block a user