Company: allowed duplicate names, made email field unique, custom migration

This commit is contained in:
eeintech 2020-10-12 17:51:48 -05:00
parent ca8472ac23
commit ac82640c6c
2 changed files with 33 additions and 2 deletions

View File

@ -0,0 +1,30 @@
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 = [
migrations.RunPython(make_empty_email_field_null),
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'),
),
migrations.AlterField(
model_name='company',
name='name',
field=models.CharField(help_text='Company name', max_length=100, verbose_name='Company name'),
),
]

View File

@ -82,7 +82,7 @@ class Company(models.Model):
class Meta:
ordering = ['name', ]
name = models.CharField(max_length=100, blank=False, unique=True,
name = models.CharField(max_length=100, blank=False,
help_text=_('Company name'),
verbose_name=_('Company name'))
@ -98,7 +98,8 @@ class Company(models.Model):
verbose_name=_('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, unique=True,
verbose_name=_('Email'), help_text=_('Contact email address'))
contact = models.CharField(max_length=100,
verbose_name=_('Contact'),