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): if self.model is None: raise ImproperlyConfigured("The list filter '%s' does not specify " "a 'model'." % self.__class__.__name__) super(ShardedFieldListFilter, self).__init__(field, request, params, model, model_admin, field_path) limit_choices_to = get_limit_choices_to_from_path(model, field_path) queryset = self.model.objects.filter(limit_choices_to) self.lookup_choices = [(obj.pk, str(obj)) for obj in queryset.distinct().order_by('pk')]