Skip to content
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'

→ Next: Collectible

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