# Path: advanced_filters/admin.py
# class AdminAdvancedFiltersMixin:
#     """ Generic AdvancedFilters mixin """
#     advanced_change_list_template = "admin/advanced_filters.html"
#     advanced_filter_form = AdvancedFilterForm
# 
#     def __init__(self, *args, **kwargs):
#         super().__init__(*args, **kwargs)
#         if self.change_list_template:
#             self.original_change_list_template = self.change_list_template
#         else:
#             self.original_change_list_template = "admin/change_list.html"
#         self.change_list_template = self.advanced_change_list_template
#         # add list filters to filters
#         self.list_filter = (AdvancedListFilters,) + tuple(self.list_filter)
# 
#     def save_advanced_filter(self, request, form):
#         if form.is_valid():
#             afilter = form.save(commit=False)
#             afilter.created_by = request.user
#             afilter.query = form.generate_query()
#             afilter.save()
#             afilter.users.add(request.user)
#             messages.add_message(
#                 request, messages.SUCCESS,
#                 _('Advanced filter added successfully.')
#             )
#             if '_save_goto' in (request.GET or request.POST):
#                 url = "{path}{qparams}".format(
#                     path=request.path, qparams="?_afilter={id}".format(
#                         id=afilter.id))
#                 return HttpResponseRedirect(url)
#         else:
#             logger.info('Failed saving advanced filter, params: %s', form.data)
# 
#     def changelist_view(self, request, extra_context=None):
#         """Add advanced_filters form to changelist context"""
#         if extra_context is None:
#             extra_context = {}
# 
#         data = None
#         if request.method == "POST":
#             if request.POST.get('action') == 'advanced_filters':
#                 data = request.POST
# 
#         form = self.advanced_filter_form(data=data, model_admin=self, extra_form=True)
#         extra_context.update({
#             'original_change_list_template': self.original_change_list_template,
#             'advanced_filters': form,
#             'current_afilter': request.GET.get('_afilter'),
#             'app_label': self.opts.app_label,
#         })
# 
#         if request.method == "POST":
#             response = self.save_advanced_filter(request, form)
#             if response:
#                 return response
# 
#         return super().changelist_view(request, extra_context=extra_context)
# 
# Path: tests/customers/models.py
# class Client(AbstractBaseUser):
#     VALID_LANGUAGES = (
#         ('en', 'English'),
#         ('sp', 'Spanish'),
#         ('it', 'Italian'),
#     )
#     USERNAME_FIELD = 'email'
# 
#     language = models.CharField(max_length=8, choices=VALID_LANGUAGES,
#                                 default='en')
#     email = models.EmailField(_('email address'), blank=True)
#     first_name = models.CharField(_('first name'), max_length=30, null=True)
#     last_name = models.CharField(_('last name'), max_length=30, blank=True)
#     is_active = models.BooleanField(
#         _('active'), default=True,
#         help_text=_('Designates whether this user should be treated as '
#                     'active. Unselect this instead of deleting accounts.'))
#     assigned_to = models.ForeignKey('reps.SalesRep', on_delete=models.CASCADE)
#     date_joined = models.DateTimeField(_('date joined'), default=timezone.now)


from django.contrib import admin
from advanced_filters.admin import AdminAdvancedFiltersMixin
from .models import Client




class ClientAdmin(AdminAdvancedFiltersMixin, admin.ModelAdmin):
    list_display = ('language', 'first_name', 'last_name', 'assigned_to', 'email')
    list_filter = ('language', 'last_name')
    advanced_filter_fields = ('language', 'first_name',

# Path: advanced_filters/admin.py
# class AdminAdvancedFiltersMixin:
#     """ Generic AdvancedFilters mixin """
#     advanced_change_list_template = "admin/advanced_filters.html"
#     advanced_filter_form = AdvancedFilterForm
# 
#     def __init__(self, *args, **kwargs):
#         super().__init__(*args, **kwargs)
#         if self.change_list_template:
#             self.original_change_list_template = self.change_list_template
#         else:
#             self.original_change_list_template = "admin/change_list.html"
#         self.change_list_template = self.advanced_change_list_template
#         # add list filters to filters
#         self.list_filter = (AdvancedListFilters,) + tuple(self.list_filter)
# 
#     def save_advanced_filter(self, request, form):
#         if form.is_valid():
#             afilter = form.save(commit=False)
#             afilter.created_by = request.user
#             afilter.query = form.generate_query()
#             afilter.save()
#             afilter.users.add(request.user)
#             messages.add_message(
#                 request, messages.SUCCESS,
#                 _('Advanced filter added successfully.')
#             )
#             if '_save_goto' in (request.GET or request.POST):
#                 url = "{path}{qparams}".format(
#                     path=request.path, qparams="?_afilter={id}".format(
#                         id=afilter.id))
#                 return HttpResponseRedirect(url)
#         else:
#             logger.info('Failed saving advanced filter, params: %s', form.data)
# 
#     def changelist_view(self, request, extra_context=None):
#         """Add advanced_filters form to changelist context"""
#         if extra_context is None:
#             extra_context = {}
# 
#         data = None
#         if request.method == "POST":
#             if request.POST.get('action') == 'advanced_filters':
#                 data = request.POST
# 
#         form = self.advanced_filter_form(data=data, model_admin=self, extra_form=True)
#         extra_context.update({
#             'original_change_list_template': self.original_change_list_template,
#             'advanced_filters': form,
#             'current_afilter': request.GET.get('_afilter'),
#             'app_label': self.opts.app_label,
#         })
# 
#         if request.method == "POST":
#             response = self.save_advanced_filter(request, form)
#             if response:
#                 return response
# 
#         return super().changelist_view(request, extra_context=extra_context)
# 
# Path: tests/customers/models.py
# class Client(AbstractBaseUser):
#     VALID_LANGUAGES = (
#         ('en', 'English'),
#         ('sp', 'Spanish'),
#         ('it', 'Italian'),
#     )
#     USERNAME_FIELD = 'email'
# 
#     language = models.CharField(max_length=8, choices=VALID_LANGUAGES,
#                                 default='en')
#     email = models.EmailField(_('email address'), blank=True)
#     first_name = models.CharField(_('first name'), max_length=30, null=True)
#     last_name = models.CharField(_('last name'), max_length=30, blank=True)
#     is_active = models.BooleanField(
#         _('active'), default=True,
#         help_text=_('Designates whether this user should be treated as '
#                     'active. Unselect this instead of deleting accounts.'))
#     assigned_to = models.ForeignKey('reps.SalesRep', on_delete=models.CASCADE)
#     date_joined = models.DateTimeField(_('date joined'), default=timezone.now)


# Path: tests/customers/admin.py
from django.contrib import admin
from advanced_filters.admin import AdminAdvancedFiltersMixin
from .models import Client





class ClientAdmin(AdminAdvancedFiltersMixin, admin.ModelAdmin):
    list_display = ('language', 'first_name', 'last_name', 'assigned_to', 'email')
    list_filter = ('language', 'last_name')
    advanced_filter_fields = ('language', 'first_name',

                              ('assigned_to__email', 'Sales Rep.'))