25 lines
594 B
Python
25 lines
594 B
Python
from django.core.validators import EMPTY_VALUES
|
|
from django_filters import rest_framework as filters
|
|
|
|
from location import models
|
|
|
|
|
|
class CityBackFilter(filters.FilterSet):
|
|
"""Employee filter set."""
|
|
|
|
search = filters.CharFilter(method='search_by_name')
|
|
|
|
class Meta:
|
|
"""Meta class."""
|
|
|
|
model = models.City
|
|
fields = (
|
|
'search',
|
|
)
|
|
|
|
def search_by_name(self, queryset, name, value):
|
|
"""Search by name or last name."""
|
|
if value not in EMPTY_VALUES:
|
|
return queryset.search_by_name(value)
|
|
return queryset
|