diff --git a/myproject/customers/filters.py b/myproject/customers/filters.py index c7becba..49028b4 100644 --- a/myproject/customers/filters.py +++ b/myproject/customers/filters.py @@ -38,9 +38,16 @@ class CustomerFilter(django_filters.FilterSet): widget=forms.CheckboxInput(attrs={'class': 'form-check-input'}) ) + # Фильтр: есть канал связи + has_contact_channel = django_filters.BooleanFilter( + method='filter_has_contact_channel', + label='Есть канал связи', + widget=forms.CheckboxInput(attrs={'class': 'form-check-input'}) + ) + class Meta: model = Customer - fields = ['has_notes', 'no_phone', 'no_email'] + fields = ['has_notes', 'no_phone', 'no_email', 'has_contact_channel'] def filter_has_notes(self, queryset, name, value): """Фильтр клиентов с заметками""" @@ -59,3 +66,12 @@ class CustomerFilter(django_filters.FilterSet): if value: return queryset.filter(email__isnull=True) | queryset.filter(email='') return queryset + + def filter_has_contact_channel(self, queryset, name, value): + """Фильтр клиентов с каналами связи (Instagram, Telegram и т.д.)""" + if value: + from .models import ContactChannel + # Возвращаем только клиентов у которых есть хотя бы один канал связи + customer_ids = ContactChannel.objects.values_list('customer_id', flat=True).distinct() + return queryset.filter(id__in=customer_ids) + return queryset diff --git a/myproject/customers/templates/customers/customer_list.html b/myproject/customers/templates/customers/customer_list.html index eeff6f4..b670e4a 100644 --- a/myproject/customers/templates/customers/customer_list.html +++ b/myproject/customers/templates/customers/customer_list.html @@ -41,7 +41,7 @@
-
+
{{ filter.form.has_notes }}
+
+ {{ filter.form.has_contact_channel }} + +
@@ -69,7 +75,7 @@ - {% if query or filter.form.has_notes.value or filter.form.no_phone.value or filter.form.no_email.value %} + {% if query or filter.form.has_notes.value or filter.form.no_phone.value or filter.form.no_email.value or filter.form.has_contact_channel.value %} Очистить