-
Notifications
You must be signed in to change notification settings - Fork 11
Views
deby edited this page Feb 26, 2018
·
1 revision
↑ Parent: MagiCollection
For each of your collections, you may enable, disable or configure views. By default, all views are enabled.
- ⎡List view⎦: Paginated list of items with filters/search
- ⎡Item view⎦: A page with a single item, shows comments for this item
- ⎡Add view⎦: Page with a form to add a new item
- ⎡Edit view⎦: Page with a form to edit and delete an item
For each view, you may also override the fields and methods. When overriding methods, it's recommended to call its super
.
from django.core.exceptions import PermissionDenied
from django.utils.translation import ugettext_lazy as _
from magi.magicollections import MagiCollection
class IdolCollection(MagiCollection):
title = _('Idol')
class ListView(MagiCollection.ListView):
staff_required = True
def check_permissions(self, request, context):
super(IdolCollection.ListView, self).check_permissions(request, context)
if request.user.username == 'bad_staff':
raise PermissionDenied()
If you need some logic behind settings that are not methods you can use @property
:
from magi.magicollections import MagiCollection
class IdolCollection(MagiCollection):
class ListView(MagiCollection.ListView):
@property
def default_ordering(self):
return '-level' if hasattr(self.collection.queryset.model, 'level') else '-id'
ℹ︎ See also: MagiCollection settings in All views
→ Next: Collectible
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