Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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,
),
]
Original file line number Diff line number Diff line change
@@ -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.",
),
),
]
11 changes: 5 additions & 6 deletions src/genlab_bestilling/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 2 additions & 5 deletions src/staff/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)
Expand Down