Skip to content

Commit

Permalink
fix(apis_entities): use generic search filter for related entity search
Browse files Browse the repository at this point in the history
  • Loading branch information
b1rger committed May 6, 2024
1 parent ea58f54 commit ae7fd87
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions apis_core/apis_entities/filtersets.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import django_filters
from django.db import models
from apis_core.generic.filtersets import GenericFilterSet, GenericFilterSetForm
from apis_core.utils.filtermethods import related_entity_name
from apis_core.apis_relations.models import Property
from apis_core.generic.helpers import generate_search_filter

ABSTRACT_ENTITY_FILTERS_EXCLUDE = [
"rootobject_ptr",
Expand All @@ -28,13 +28,18 @@ def related_property(queryset, name, value):
return queryset


def related_entity(queryset, name, value):
search_filter = generate_search_filter(queryset.model, value)
return queryset.filter(search_filter)


class AbstractEntityFilterSetForm(GenericFilterSetForm):
columns_exclude = ABSTRACT_ENTITY_FILTERS_EXCLUDE


class AbstractEntityFilterSet(GenericFilterSet):
related_entity_name = django_filters.CharFilter(
method=related_entity_name, label="Related entity"
related_entity = django_filters.CharFilter(
method=related_entity, label="Related entity contains"
)
related_property = django_filters.ModelChoiceFilter(
queryset=Property.objects.all().order_by("name_forward"),
Expand Down

0 comments on commit ae7fd87

Please sign in to comment.