-
Notifications
You must be signed in to change notification settings - Fork 11
MagiFiltersForm settings
deby edited this page Dec 6, 2021
·
4 revisions
↑ Parent: References
← Previous: MagiForm settings
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
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
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
→ Next: Single pages settings
I. Introduction
II. Tutorials
III. References
- Files tree
- Default collections
- Default pages
- Website settings
- MagiCollection settings
- Abstract models
- Abstract collections
- MagiForm settings
- MagiFiltersForm settings
- Single pages settings
IV. Utils
-
MagiModel utils
- MagiModel images and files
- DateTime fields
- BaseAccount model
- Save choices values as integer rather than strings
- Store comma separated values
- Store dictionaries
- Store Markdown texts
- Translate fields values in multiple languages
- Store JSON
- More model field types
- Transform images before saving them
- Check choices at form level instead of model level
- Use an internal cache for foreign keys in models
- Customize views with MagiModel properties
- Events
- Form utils
- Python utils
- Templates utils
- Javascript utils
- Enable and disable existing collections and pages
- Translations
- Page titles and descriptions
- Characters
- Seasons
- Roles and permissions
- Allow your staff team to change configurations
- Custom users preferences and settings
- Background illustrations
- Activities tabs
- Corner popups
VI. More