Filters

When you specify the fields attribute on a FilterSet subclass, various different Filter classes will be chosen depending on the type of field. They are listed below, with the keyword argument options that they take.

At the moment, all other methods of Filter and subclasses are considered private implementation details, until all the Filters are implemented and the API firms up.

class django_easyfilters.filters.Filter

This is the base class for all filters, and has provides some options:

  • query_param:

    The parameter in the query string that will be used for this field. This can be useful for shortening the query strings that are generated.

  • order_by_count:

    Default: False

    If True, this will cause the choices to be sorted so that the choices with the largest ‘count’ appear first.

class django_easyfilters.filters.ForeignKeyFilter

This is used for ForeignKey fields

class django_easyfilters.filters.ManyToManyFilter

This is used for ManyToMany fields

class django_easyfilters.filters.ChoicesFilter

This is used for fields that have ‘choices’ defined. The choices presented will be in the order specified in ‘choices’.

class django_easyfilters.filters.DateTimeFilter

This is the most complex of the filters, as it allows drill-down from year to month to day. It takes the following options:

  • max_links

    Default: 12

    The maximum number of links to display. If the number of choices at any level does not fit into this value, ranges will be used to shrink the number of choices.

  • max_depth

    Default: None

    If 'year' or 'month' is specified, the drill-down will be limited to that level.

class django_easyfilters.filters.ValuesFilter

This is the fallback that is used when nothing else matches.

Project Versions

Previous topic

FilterSet

Next topic

Development

This Page