Clean up unique on existing models
This commit is contained in:
parent
a44ac2fa81
commit
49eacdeef4
16 changed files with 141 additions and 12 deletions
|
@ -80,6 +80,10 @@ class Migration(migrations.Migration):
|
|||
name='measurementunit',
|
||||
unique_together=set([('name', 'code')]),
|
||||
),
|
||||
migrations.AlterUniqueTogether(
|
||||
name='measurementtype',
|
||||
unique_together=set([('name', 'code', 'measurement_type_class')]),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='measurementtype',
|
||||
name='default_measurement_unit',
|
||||
|
@ -123,4 +127,8 @@ class Migration(migrations.Migration):
|
|||
name='default_measurement_unit',
|
||||
field=models.ForeignKey(blank=True, to='misc.MeasurementUnit', related_name='measurement_types', null=True),
|
||||
),
|
||||
migrations.AlterUniqueTogether(
|
||||
name='container',
|
||||
unique_together=set([('name', 'code', 'color', 'material', 'volume')]),
|
||||
),
|
||||
]
|
||||
|
|
|
@ -30,6 +30,7 @@ class MeasurementType(models.Model):
|
|||
return self.name
|
||||
|
||||
class Meta:
|
||||
unique_together = ('name', 'code', 'measurement_type_class')
|
||||
ordering = ['sort_order']
|
||||
|
||||
|
||||
|
@ -79,4 +80,5 @@ class Container(models.Model):
|
|||
return self.name
|
||||
|
||||
class Meta:
|
||||
unique_together = ('name', 'code', 'color', 'material', 'volume')
|
||||
ordering = ['sort_order']
|
||||
|
|
|
@ -26,6 +26,14 @@ class MeasurementTypeTestCase(TestCase):
|
|||
self.assertTrue(isinstance(m, MeasurementType))
|
||||
self.assertEqual(m.__str__(), m.name)
|
||||
|
||||
def test_uniqueness(self):
|
||||
m1 = MeasurementTypeFactory()
|
||||
with transaction.atomic(), self.assertRaises(IntegrityError):
|
||||
MeasurementTypeFactory(name=m1.name, code=m1.code,
|
||||
measurement_type_class=m1.measurement_type_class)
|
||||
m3 = MeasurementTypeFactory()
|
||||
self.assertTrue(isinstance(m3, MeasurementType))
|
||||
|
||||
|
||||
class MaterialTestCase(TestCase):
|
||||
def test_creation(self):
|
||||
|
@ -60,3 +68,11 @@ class ContainerTestCase(TestCase):
|
|||
c = ContainerFactory()
|
||||
self.assertTrue(isinstance(c, Container))
|
||||
self.assertEqual(c.__str__(), c.name)
|
||||
|
||||
def test_uniqueness(self):
|
||||
c1 = ContainerFactory()
|
||||
with transaction.atomic(), self.assertRaises(IntegrityError):
|
||||
ContainerFactory(name=c1.name, code=c1.code, color=c1.color,
|
||||
material=c1.material, volume=c1.volume)
|
||||
c3 = ContainerFactory()
|
||||
self.assertTrue(isinstance(c3, Container))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue