Queries

class ajaxviews.queries.AjaxQuerySet(model=None, query=None, using=None, hints=None)[source]

Bases: django.db.models.query.QuerySet

This QuerySet enhances generic filter options that work together with server side ajaxviews.views.AjaxListView and client side FilterView. You can instantiate the QuerySet as manager to your models to enable default filtering.

Filter and sorting options passed through json_cfg and applied to filter_fields:
  • sort_index List index of field to sort by.
  • sort_order Order fields by asc, desc or none.
  • filter_index List index of field to filter results. This displays all possible filter options.
  • selected_filter_index Field of filter to apply on queryset.
  • selected_filter_values Values to filter by on selected field.
Variables:distinct_qs (bool) – Apply distinct filter option. Default is True.
default_filter(opts, *args, **kwargs)[source]

This is called by the view’s get_queryset method.

It calls the ajax_filter() first to apply the filter and then ajax_sort() to sort the filtered QuerySet. Each of these methods can be overridden to manipulate the QuerySet.

Parameters:
  • opts – Filter options passed through request.
  • args – Positional filter options in addition to opts.
  • kwargs – Keword filter options in addition to opts.
Returns:

Filtered QuerySet

get_unique_values(field)[source]

Used to get unique values of a given field.

Parameters:field – Name of the field
Returns:List of field values