diff --git a/src/genlab_bestilling/migrations/0031_delete_all_isolationmethods.py b/src/genlab_bestilling/migrations/0031_delete_all_isolationmethods.py new file mode 100644 index 00000000..f11d56f0 --- /dev/null +++ b/src/genlab_bestilling/migrations/0031_delete_all_isolationmethods.py @@ -0,0 +1,32 @@ +# Generated by Django 5.2.3 on 2025-07-22 10:26 + +from django.db import migrations +from django.db.migrations.state import StateApps +from django.db.backends.base.schema import BaseDatabaseSchemaEditor + + +def delete_isolation_methods(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor): + IsolationMethod = apps.get_model("genlab_bestilling", "IsolationMethod") + IsolationMethod.objects.all().delete() + + +def reverse_delete_isolation_methods( + apps: StateApps, schema_editor: BaseDatabaseSchemaEditor +): + pass + + +class Migration(migrations.Migration): + dependencies = [ + ( + "genlab_bestilling", + "0030_samplemarkeranalysis_has_pcr_and_more", + ), + ] + + operations = [ + migrations.RunPython( + delete_isolation_methods, + reverse_delete_isolation_methods, + ), + ] diff --git a/src/genlab_bestilling/migrations/0032_alter_isolationmethod_remove_species_add_type_20250722_1226.py b/src/genlab_bestilling/migrations/0032_alter_isolationmethod_remove_species_add_type_20250722_1226.py new file mode 100644 index 00000000..6ee93a71 --- /dev/null +++ b/src/genlab_bestilling/migrations/0032_alter_isolationmethod_remove_species_add_type_20250722_1226.py @@ -0,0 +1,26 @@ +# Generated by Django 5.2.3 on 2025-07-22 10:26 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ( + "genlab_bestilling", + "0031_delete_all_isolationmethods", + ), + ] + + operations = [ + migrations.RemoveField(model_name="isolationmethod", name="species"), + migrations.AddField( + model_name="isolationmethod", + name="type", + field=models.ForeignKey( + to="genlab_bestilling.sampletype", + on_delete=models.CASCADE, + related_name="type_isolation_methods", + help_text="The sample type this isolation method is related to.", + ), + ), + ] diff --git a/src/genlab_bestilling/models.py b/src/genlab_bestilling/models.py index 25672803..14a06c0a 100644 --- a/src/genlab_bestilling/models.py +++ b/src/genlab_bestilling/models.py @@ -816,13 +816,12 @@ def __str__(self) -> str: class IsolationMethod(models.Model): - name = models.CharField(max_length=255, unique=False) - species = models.ForeignKey( - f"{an}.Species", + name = models.CharField(max_length=255) + type = models.ForeignKey( + f"{an}.SampleType", on_delete=models.CASCADE, - related_name="species_isolation_methods", - help_text="The species this isolation method is related to.", - default=None, + related_name="type_isolation_methods", + help_text="The sample type this isolation method is related to.", ) def __str__(self) -> str: diff --git a/src/staff/views.py b/src/staff/views.py index d3222144..58d4ca14 100644 --- a/src/staff/views.py +++ b/src/staff/views.py @@ -560,12 +560,9 @@ def get_queryset(self) -> QuerySet[Sample]: return Sample.objects.filter(order=self.get_order(), genlab_id__isnull=False) def get_isolation_methods(self) -> QuerySet[IsolationMethod, str]: - species_ids = ( - self.get_queryset().values_list("species_id", flat=True).distinct() - ) - + types = self.get_queryset().values_list("type", flat=True).distinct() return ( - IsolationMethod.objects.filter(species_id__in=species_ids) + IsolationMethod.objects.filter(type__in=types) .values_list("name", flat=True) .distinct() )