mirror of
https://github.com/inventree/InvenTree.git
synced 2025-05-02 05:26:45 +00:00
Merge pull request #1043 from eeintech/unique_email_company
[Company] Allow duplicate names - Unique name/email pair
This commit is contained in:
commit
5e63ccc9f6
@ -0,0 +1,38 @@
|
|||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
def make_empty_email_field_null(apps, schema_editor):
|
||||||
|
Company = apps.get_model('company', 'Company')
|
||||||
|
for company in Company.objects.all():
|
||||||
|
if company.email == '':
|
||||||
|
company.email = None
|
||||||
|
company.save()
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('company', '0023_auto_20200808_0715'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
# Allow email field to be NULL
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='company',
|
||||||
|
name='email',
|
||||||
|
field=models.EmailField(blank=True, help_text='Contact email address', max_length=254, null=True, unique=False, verbose_name='Email'),
|
||||||
|
),
|
||||||
|
# Convert empty email string to NULL
|
||||||
|
migrations.RunPython(make_empty_email_field_null),
|
||||||
|
# Remove unique constraint on name field
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='company',
|
||||||
|
name='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,8 +81,11 @@ 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, unique=True,
|
name = models.CharField(max_length=100, blank=False,
|
||||||
help_text=_('Company name'),
|
help_text=_('Company name'),
|
||||||
verbose_name=_('Company name'))
|
verbose_name=_('Company name'))
|
||||||
|
|
||||||
@ -98,7 +101,8 @@ 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, verbose_name=_('Email'), help_text=_('Contact email address'))
|
email = models.EmailField(blank=True, null=True,
|
||||||
|
verbose_name=_('Email'), help_text=_('Contact email address'))
|
||||||
|
|
||||||
contact = models.CharField(max_length=100,
|
contact = models.CharField(max_length=100,
|
||||||
verbose_name=_('Contact'),
|
verbose_name=_('Contact'),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user