def __init__(self, f, request, params, model, model_admin, field_path=None): super(CustomQuerysetAllValuesFilterSpec, self).__init__( f, request, params, model, model_admin, field_path=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) 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(f.name).values_list(f.name, flat=True)
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) 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)
def __init__(self, f, request, params, model, model_admin, field_path=None): super(AllValuesFilterSpec, self).__init__(f, request, params, model, model_admin, field_path=field_path) self.lookup_kwarg = self.field_path self.lookup_kwarg_isnull = '%s__isnull' % self.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, self.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) def uniquify(coll): """enforces uniqueness while preserving order""" seen = set() return [x for x in coll if x not in seen and not seen.add(x)] self.lookup_choices = \ uniquify(queryset.order_by(f.name).values_list(f.name, flat=True))
def __init__(self, f, request, params, model, model_admin, field_path=None): super(AllValuesFilterSpec, self).__init__(f, request, params, model, model_admin, field_path=field_path) self.lookup_kwarg = self.field_path self.lookup_kwarg_isnull = '%s__isnull' % self.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, self.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(f.name).values_list(f.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, 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, f, request, params, model, model_admin, field_path=None): super(AllValuesFilterSpec, self).__init__(f, request, params, model, model_admin, field_path=field_path) self.lookup_val = request.GET.get(self.field_path, 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(f.name).values(f.name)
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() 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, field_path, index): super(AllValuesFieldFilter, self).__init__( field, field_path, index) model = self.resource.model self.lookup_kwarg = field_path self.lookup_kwarg_isnull = '%s__isnull' % field_path 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))