Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(apis_entities): use generic search filter for related entity search #811

Merged
merged 1 commit into from
May 7, 2024
Merged
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
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
Loading