#[derive(FilterableWithPersianRug)]
{
    // Attributes available to this derive:
    #[django]
}
Available on crate features filter and persian-rug only.
Expand description

Derive the FilterableWithContext trait for persian-rug 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 field 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 django-query.

  • #[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.

The struct itself must also be annotated with the django attribute, which gives the persian-rug constraints to apply to to each derived impl:

  • #[django(persian_rug(context=Rug))] The persian-rug context type for this type is Rug.

  • #[django(persian_rug(context=C, access(Foo<C>)))] The persian-rug context type is the template parameter C. The context must provide access to Foo<C>.