Derive Macro Filterable

Source
#[derive(Filterable)]
{
    // Attributes available to this derive:
    #[django]
}
Available on crate feature filter only.
Expand description

Derive the Filterable trait, creating suitable FilterClass types.

This is only implemented for structs with named fields. All fields will be exposed, with a default operator of exact unless annotated to indicate otherwise. The annotations use the django attribute, which has the following options:

  • #[django(rename="new_name")] Expose the annotated member for filtering as `new_name instead of using its name in the source code.

  • #[django(default_op=iexact)] Set the default operator, which is applied when the field is referred to directly to be iexact, where iexact can be replaced with any of the built-in operators included in this crate.

  • #[django(default_fun=my_crate::MyOperatorClass)] Set the default operator to be the custom type my_crate::MyOperatorClass, which must implement OperatorClass.]

  • #[django(exclude)] Do not expose this field, it cannot be used in filtering.

  • #[django(traverse)] This type of this field is itself Filterable and nested filters onto its members are permitted via the double underscore syntax that Django uses.

  • #[django(op(in, icontains))] In addition to the default operator, this field can also be filtered on using in and icontains, using double underscores to separate the operator from the field name.

  • #[django(op(foo=my_crate::MyOperatorClass))] This field has a custom filter operator foo which can be appended to its name with double underscores, and which when used, creates a filter using my_crate::MyOperatorClass, which must itself be an instance of OperatorClass.