diff --git a/backend/django/core/models.py b/backend/django/core/models.py index fb187cfa..cf33beb2 100644 --- a/backend/django/core/models.py +++ b/backend/django/core/models.py @@ -416,10 +416,12 @@ def __str__(self): return self.field_name def get_unique_options(self): - unique_list = list( - set(self.labelmetadata_set.all().values_list("value", flat=True)) + unique_list = ( + self.labelmetadata_set.all() + .order_by("value") + .values_list("value", flat=True) + .distinct() ) - unique_list.sort() return unique_list diff --git a/backend/django/core/views/api_annotate.py b/backend/django/core/views/api_annotate.py index 98de28d6..75398dd0 100644 --- a/backend/django/core/views/api_annotate.py +++ b/backend/django/core/views/api_annotate.py @@ -79,12 +79,17 @@ def get_queryset(self): filter_text = self.request.GET.get("searchString") label_category = self.request.GET.get("category") - if label_category and label_category != "all": - if label_category == "None": - category_label_list = LabelMetaData.objects.filter( - label_metadata_field=project.category.label_metadata_field, - value="nan", - ).values_list("label__pk", flat=True) + if hasattr(project, "category") and label_category != "all": + if label_category == "None" or label_category == "": + category_label_list = ( + LabelMetaData.objects.filter( + label_metadata_field=project.category.label_metadata_field + ) + .filter( + Q(value__isnull=True) | Q(value="nan"), + ) + .values_list("label__pk", flat=True) + ) else: category_label_list = LabelMetaData.objects.filter( label_metadata_field=project.category.label_metadata_field,