mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-11-04 15:15:42 +00:00 
			
		
		
		
	Company: allowed duplicate names, made email field unique, custom migration
This commit is contained in:
		
							
								
								
									
										30
									
								
								InvenTree/company/migrations/0024_auto_20201012_2238.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								InvenTree/company/migrations/0024_auto_20201012_2238.py
									
									
									
									
									
										Normal 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'),
 | 
			
		||||
        ),
 | 
			
		||||
    ]
 | 
			
		||||
@@ -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'),
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user