def __init__(self, field, request, params, model, model_admin, field_path): self.lookup_kwarg = field_path self.lookup_kwarg_isnull = '%s__isnull' % field_path self.lookup_val = request.GET.get(self.lookup_kwarg, None) self.lookup_val_isnull = request.GET.get(self.lookup_kwarg_isnull, None) parent_model, reverse_path = reverse_field_path(model, field_path) # Obey parent ModelAdmin queryset when deciding which options to show if model == parent_model: queryset = model_admin.get_queryset(request) else: queryset = parent_model._default_manager.all() # optional feature: limit choices base on existing relationships # queryset = queryset.complex_filter( # {'%s__isnull' % reverse_path: False}) limit_choices_to = get_limit_choices_to_from_path(model, field_path) queryset = queryset.filter(limit_choices_to) self.lookup_choices = (queryset .distinct() .order_by(field.name) .values_list(field.name, flat=True)) super(AllValuesFieldListFilter, self).__init__( field, request, params, model, model_admin, field_path)
def __init__(self, field, request, params, model, model_admin, field_path): self.lookup_kwarg = field_path self.lookup_kwarg_isnull = '%s__isnull' % field_path self.lookup_val = params.get(self.lookup_kwarg) self.lookup_val_isnull = params.get(self.lookup_kwarg_isnull) self.empty_value_display = model_admin.get_empty_value_display() parent_model, reverse_path = reverse_field_path(model, field_path) # Obey parent ModelAdmin queryset when deciding which options to show if model == parent_model: queryset = model_admin.get_queryset(request) else: queryset = parent_model._default_manager.all() self.lookup_choices = queryset.distinct().order_by(field.name).values_list(field.name, flat=True) super().__init__(field, request, params, model, model_admin, field_path)
def __init__(self, field, request, params, model, model_admin, field_path): self.lookup_kwarg = field_path self.lookup_kwarg_isnull = '%s__isnull' % field_path self.lookup_val = params.get(self.lookup_kwarg) self.lookup_val_isnull = params.get(self.lookup_kwarg_isnull) self.empty_value_display = model_admin.get_empty_value_display() parent_model, reverse_path = reverse_field_path(model, field_path) # Obey parent ModelAdmin queryset when deciding which options to show if model == parent_model: queryset = model_admin.get_queryset(request) else: queryset = parent_model._default_manager.all() self.lookup_choices = queryset.distinct().order_by( field.name).values_list(field.name, flat=True) super().__init__(field, request, params, model, model_admin, field_path)
def __init__(self, field, request, params, model, model_admin, field_path): self.lookup_kwarg = field_path self.lookup_kwarg_isnull = '%s__isnull' % field_path self.lookup_val = request.GET.get(self.lookup_kwarg) self.lookup_val_isnull = request.GET.get(self.lookup_kwarg_isnull) self.empty_value_display = model_admin.get_empty_value_display() parent_model, reverse_path = reverse_field_path(model, field_path) # Obey parent ModelAdmin queryset when deciding which options to show if model == parent_model: queryset = model_admin.get_queryset(request) else: queryset = parent_model._default_manager.all() self.lookup_choices = queryset.values(field.name).annotate( the_count=Count(field.name)).order_by(field.name) super(DistinctChoicesFilter, self).__init__(field, request, params, model, model_admin, field_path)
def __init__(self, field, request, params, model, model_admin, field_path): self.lookup_kwarg = field_path self.lookup_kwarg_isnull = '%s__isnull' % field_path self.lookup_val = request.GET.get(self.lookup_kwarg, None) self.lookup_val_isnull = request.GET.get(self.lookup_kwarg_isnull, None) parent_model, reverse_path = reverse_field_path(model, field_path) # Obey parent ModelAdmin queryset when deciding which options to show if model == parent_model: queryset = model_admin.get_queryset(request) else: queryset = parent_model._default_manager.all() self.lookup_choices = (queryset .distinct() .order_by(field.name) .values_list(field.name, flat=True)) super(AllValuesFieldListFilter, self).__init__( field, request, params, model, model_admin, field_path)
def __init__(self, field, request, params, model, model_admin, field_path): self.lookup_kwarg = field_path self.lookup_kwarg_isnull = '%s__isnull' % field_path self.lookup_val = request.GET.get(self.lookup_kwarg, None) self.lookup_val_isnull = request.GET.get(self.lookup_kwarg_isnull, None) parent_model, reverse_path = reverse_field_path(model, field_path) queryset = parent_model._default_manager.all() # optional feature: limit choices base on existing relationships # queryset = queryset.complex_filter( # {'%s__isnull' % reverse_path: False}) limit_choices_to = get_limit_choices_to_from_path(model, field_path) queryset = queryset.filter(limit_choices_to) self.lookup_choices = (queryset.distinct().order_by( field.name).values_list(field.name, flat=True)) super(AllValuesFieldListFilter, self).__init__(field, request, params, model, model_admin, field_path)
def __init__(self, field, request, params, model, model_admin, field_path): self.lookup_kwarg = '%s__in' % field_path self.lookup_kwarg_isnull = '%s__isnull' % field_path lookup_vals = request.GET.get(self.lookup_kwarg) self.lookup_vals = lookup_vals.split(',') if lookup_vals else list() self.lookup_val_isnull = request.GET.get(self.lookup_kwarg_isnull) self.empty_value_display = model_admin.get_empty_value_display() parent_model, reverse_path = reverse_field_path(model, field_path) # Obey parent ModelAdmin queryset when deciding which options to show if model == parent_model: queryset = model_admin.get_queryset(request) else: queryset = parent_model._default_manager.all() self.lookup_choices = (queryset .distinct() .order_by(field.name) .values_list(field.name, flat=True)) super(admin.AllValuesFieldListFilter, self).__init__(field, request, params, model, model_admin, field_path) self.used_parameters = self.prepare_used_parameters(self.used_parameters)
def __init__(self, field, request, params, model, model_admin, field_path): super(CustomQuerysetAllValuesFieldListFilter, self).__init__( field, request, params, model, model_admin, field_path) parent_model, reverse_path = reverse_field_path(model, self.field_path) queryset = parent_model._default_manager.all() qs_dict = getattr(model_admin, 'queryset_filter', None) if qs_dict and field_path in qs_dict: queryset = qs_dict[field_path] if isinstance(queryset, str): # Define title if hasattr(getattr(model_admin, queryset), 'short_description'): self.title = getattr(getattr(model_admin, queryset), 'short_description') queryset = getattr(model_admin, queryset)(request) self.lookup_choices = queryset.distinct().order_by(field.name).values_list(field.name, flat=True)
def __init__(self, field, request, params, model, model_admin, field_path): self.lookup_kwarg = field_path self.lookup_kwarg_isnull = '%s__isnull' % field_path self.lookup_val = request.GET.get(self.lookup_kwarg) self.lookup_val_isnull = request.GET.get(self.lookup_kwarg_isnull) self.empty_value_display = model_admin.get_empty_value_display() parent_model, reverse_path = reverse_field_path(model, field_path) # Obey parent ModelAdmin queryset when deciding which options to show if model == parent_model: queryset = model_admin.get_queryset(request) else: queryset = parent_model._default_manager.all() if self.lookup_kwarg == 'talent__average_rating': queryset = filter_lookups_related_queryset( request, queryset, lookup_kwarg=self.lookup_kwarg) else: queryset = filter_lookups_queryset(request, queryset, lookup_kwarg=self.lookup_kwarg) self.lookup_choices = (queryset.distinct().order_by( field.name).values_list(field.name, flat=True)) super(FilteredAllValuesFieldListFilter, self).__init__(field, request, params, model, model_admin, field_path)
def __init__(self, field, request, params, model, model_admin, field_path): self.lookup_kwarg = field_path + '__in' self.lookup_kwarg_isnull = field_path + '__isnull' super().__init__(field, request, params, model, model_admin, field_path) self.title = self.get_title() self.change_list_template = 'admin/change_list_filter_sidebar.html' self.lookup_val = self.used_parameters.get(self.lookup_kwarg, []) if len(self.lookup_val) == 1 and self.lookup_val[0] == '': self.lookup_val = [] self.lookup_val_isnull = self.used_parameters.get( self.lookup_kwarg_isnull) self.empty_value_display = model_admin.get_empty_value_display() parent_model, reverse_path = reverse_field_path(model, field_path) # Obey parent ModelAdmin queryset when deciding which options to show if model == parent_model: queryset = model_admin.get_queryset(request) else: queryset = parent_model._default_manager.all() self.lookup_choices = queryset.distinct().order_by( field.name).values_list(field.name, flat=True)
"""