python - Hide filter items that produce zero results in django-filter -


I have an issue with the Dzegoo-Filters app: Zero results will hide the items that arise. I think that There is a simple way to do this, but how does the idak happen.

I am using LinkWidget on a ModelChoiceFilter, such as:

  provider = django_filters ModelChoiceFilter (queryset = Provider.objects.all ()), widget = django_filters. Widgets.LinkWidget  

What I need to do is filter the query and select only the provider that will produce at least one result, and exclude others. Is there a way to do this?

Actually, you need to apply a filter, and then apply it again, but new Something similar to the generated query:

  f = someFilter (request.GET) f = someFilter (request.GET, queryset = f.qs)  

Now that you have the right query set, you can dynamically override providers in init :

  def __init __ (auto, ** kw): Super (some filters, self) .__ init __ (** kw) self.filters ['provider']. Extra ['queryset'] = Provider Objects.filter (foo__in = self.queryset)  

Not very good but it works. You must be sure to put those two calls in a more efficient method on the filter.


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -