Create a custom list filter class. There's an example in the docs
which can be adopted to your case.
from django.contrib import admin
class ValidPhoneListFilter(admin.SimpleListFilter):
# Human-readable title which will be displayed in the
# right admin sidebar just above the filter options.
title = _('valid phone')
parameter_name = 'valid_phone'
def lookups(self, request, model_admin):
return (
('valid', _('valid phone')),
('invalid', _('invalid phone')),
)
def queryset(self, request, queryset):
if self.value() == 'valid':
return queryset.filter(phone__regex=r'^\d{10}$')
if self.value() == 'invalid':
return queryset.exclude(phone__regex=r'^\d{10}$')
Then include your list filter class in list_filter
for your model admin.
class PersonAdmin(admin.ModelAdmin):
list_filter = (ValidPhoneListFilter,)