-
Notifications
You must be signed in to change notification settings - Fork 11
Item Types
↑ Parent: MagiCollection
← Previous: Alt views
You may display different forms and URLs to add an item depending on "types".
When you use types on a collection, its model must have a type
(ie we should be able to do instance.type
), which can be stored in database or returned with @property
. It'll be used to retrieve the right form when editing.
For example, let's say we have 3 types of cards: Normal, Rare and Super Rare and we want to use different forms for those. Our collection will look like that:
class CardCollection(MagiCollection):
...
types = {
'normal': { ... },
'rare': { ... },
'superrare': { ... },
}
For each type, you may specify the following settings in its dictionary:
Key | Value | Default | Example |
---|---|---|---|
form_class |
FormClass to add/edit the item, must take request (make it inherit from FormWithRequest), can be a function that takes request, context and collection | required | Example |
title |
Localized title of the type | type (key) | _('Rare') |
plural_title |
Localized plural title of the type |
title value |
_('Reports') |
image |
Path of an image displayed near the title of the form that illustrates the type | None | 'rarity/ur.png' |
icon |
Icon displayed near the title of the form that illustrates the type | None | 'idolized' |
The type will be passed to the formClass when it's initialized, which allows you to reuse the same form class for all your types if you'd like.
It's also possible to check for permissions to add differently based on type by overriding the method check_type_permissions
in Add view. The method takes request, context, type
as parameters.
→ Next: API
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