from django_filters import rest_framework as filters
from geo_regions.models import GeoRegion


class GeoRegionFilter(filters.FilterSet):
    name = filters.CharFilter(lookup_expr='icontains')
    parent_id = filters.CharFilter(method='parent_id_filter')


    class Meta:
        model = GeoRegion
        fields = []

    def parent_id_filter(self, queryset, name, value):
        try:
            int_val = int(value)
        except ValueError:
            int_val = 0
        if value == 'null' or int_val < 1:
            return queryset.filter(parent_id__isnull=True)
        return queryset.filter(parent_id=int_val)

6c570115b2b6f81e07319671a8d67788fd7cd723
<mask token>


class GeoRegionFilter(filters.FilterSet):
    <mask token>
    <mask token>


    class Meta:
        model = GeoRegion
        fields = []
    <mask token>

<mask token>


class GeoRegionFilter(filters.FilterSet):
    <mask token>
    <mask token>


    class Meta:
        model = GeoRegion
        fields = []

    def parent_id_filter(self, queryset, name, value):
        try:
            int_val = int(value)
        except ValueError:
            int_val = 0
        if value == 'null' or int_val < 1:
            return queryset.filter(parent_id__isnull=True)
        return queryset.filter(parent_id=int_val)

<mask token>


class GeoRegionFilter(filters.FilterSet):
    name = filters.CharFilter(lookup_expr='icontains')
    parent_id = filters.CharFilter(method='parent_id_filter')


    class Meta:
        model = GeoRegion
        fields = []

    def parent_id_filter(self, queryset, name, value):
        try:
            int_val = int(value)
        except ValueError:
            int_val = 0
        if value == 'null' or int_val < 1:
            return queryset.filter(parent_id__isnull=True)
        return queryset.filter(parent_id=int_val)

from django_filters import rest_framework as filters
from geo_regions.models import GeoRegion


class GeoRegionFilter(filters.FilterSet):
    name = filters.CharFilter(lookup_expr='icontains')
    parent_id = filters.CharFilter(method='parent_id_filter')


    class Meta:
        model = GeoRegion
        fields = []

    def parent_id_filter(self, queryset, name, value):
        try:
            int_val = int(value)
        except ValueError:
            int_val = 0
        if value == 'null' or int_val < 1:
            return queryset.filter(parent_id__isnull=True)
        return queryset.filter(parent_id=int_val)
