diff --git a/src/genlab_bestilling/migrations/0012_sample_unique_genlab_id.py b/src/genlab_bestilling/migrations/0012_sample_unique_genlab_id.py new file mode 100644 index 0000000..553a92e --- /dev/null +++ b/src/genlab_bestilling/migrations/0012_sample_unique_genlab_id.py @@ -0,0 +1,18 @@ +# Generated by Django 5.1.3 on 2024-12-04 10:10 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("genlab_bestilling", "0011_extractplateposition_notes_and_more"), + ] + + operations = [ + migrations.AddConstraint( + model_name="sample", + constraint=models.UniqueConstraint( + fields=("genlab_id",), name="unique_genlab_id" + ), + ), + ] diff --git a/src/genlab_bestilling/models.py b/src/genlab_bestilling/models.py index e7443a6..83e4abe 100644 --- a/src/genlab_bestilling/models.py +++ b/src/genlab_bestilling/models.py @@ -316,6 +316,11 @@ class Sample(models.Model): def __str__(self) -> str: return self.genlab_id or f"#SMP_{self.id}" + class Meta: + constraints = [ + models.UniqueConstraint(fields=["genlab_id"], name="unique_genlab_id") + ] + @property def has_error(self): if not all( @@ -370,7 +375,6 @@ class ExtractPlatePosition(models.Model): extracted_at = models.DateTimeField(auto_now=True) notes = models.CharField(null=True, blank=True) - # TODO: unique position per plate class Meta: constraints = [ models.UniqueConstraint(