Skip to content

MagiFiltersForm settings

deby edited this page Dec 6, 2021 · 4 revisions

↑ Parent: References

← Previous: MagiForm settings

Configure fields

In your MagiFiltersForm, you may configure your fields using MagiFilter objects, which take the following named parameters:

Name Description Default Example
allow_csv When multiple is unabled or the field is a MultipleChoiceField, is it allowed to provide values as comma separated? Example: ?rarity=SR,UR. When csv is not allowed, values must be provided as a list like so: ?rarity=SR&rarity=UR True
distinct Makes sure results are only returned once. It makes the query slower, so it should only be used if there's a chance this may happen. False
multiple allow multiple values separated by commas. Set to False if your value may contain commas. True
noop Will not affect the queryset. Useful when you need a GET parameter that does something else than filtering, such as changing the way items are displayed. False
operator_for_multiple When multiple is enabled, what should be the operation? Choices are: OrContains, OrExact or And. Depends on field type. MagiFilterOperator.OrExact
operator_for_multiple_selectors When there are multiple selectors, what should be the operation? Choices are Or or And. Or MagiFilterOperatorSelector.And
selector will be the name of the field by default None (will use the name of the filter field) 'owner__username'
selectors same as selector but works with multiple values. None (will use selector) ['card__name', 'card__japanese_name']
to_queryset function that takes form, queryset, request, value and returns a queryset. Optional, will filter automatically. selector, selectors and multiple are ignored when specified. None (default behavior) lambda form, queryset, request, value: queryset.filter(name__in=['a', 'b'] if value == 'a_or_b' else queryset)
to_value function that takes the value and transforms the value if needed. May receive a string or a list. None (will not transform the value) lambda value: value + 1

Extra buttons

extra_buttons is expected to return an ordered dict containing:

Key Description Default
icon The Flaticon Required
verbose_name The text displayed when you put your mouse over the icon Required
url What the button links to Required
new_tab Should the link open in a new tab? False
ajax_callback Which Javascript function to call when the button exists. It will be called when the page is loaded, and it's your job to add an event handler on click, for example. None
attributes HTML attributes {}
insert_in_sidebar Any extra HTML that needs to be inserted in the sidebar, before the button. Can be useful to include hidden data None

Presets

presets needs to be specified as a dict in your filter form.

The keys correspond to the name of the preset + the URL. It needs to be simple and easily human-readable.

The values are dict with details of the preset:

Key Description Default
fields dict of field name and value, as it would be set by a form filled by a user Required
verbose_name Verbose name of the preset. Example: _('Rare') Required
label Label of the preset. All {verbose_name} {collection_plural_title} Example: "All rare cards"
icon Flaticon displayed next to the label None
image Image displayed next to the label None

ℹ︎ See also: MagiFiltersForm

I. Introduction

II. Tutorials

  1. Collections
    1. MagiModel
    2. MagiCollection
    3. MagiForm
    4. MagiFiltersForm
    5. MagiFields
  2. Single pages
  3. Configuring the navbar

III. References

IV. Utils

V. Advanced tutorials

VI. More

Clone this wiki locally