wagtail_hooks.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. from wagtail.contrib.modeladmin.options import (
  2. ModelAdmin, ModelAdminGroup, modeladmin_register)
  3. from bakerydemo.breads.models import Country, BreadIngredient, BreadType
  4. from bakerydemo.base.models import People, FooterText
  5. '''
  6. N.B. To see what icons are available for use in Wagtail menus and StreamField block types,
  7. enable the styleguide in settings:
  8. INSTALLED_APPS = (
  9. ...
  10. 'wagtail.contrib.styleguide',
  11. ...
  12. )
  13. or see https://thegrouchy.dev/general/2015/12/06/wagtail-streamfield-icons.html
  14. This demo project includes the full font-awesome set via CDN in base.html, so the entire
  15. font-awesome icon set is available to you. Options are at https://fontawesome.com/icons .
  16. '''
  17. class BreadIngredientAdmin(ModelAdmin):
  18. # These stub classes allow us to put various models into the custom "Wagtail Bakery" menu item
  19. # rather than under the default Snippets section.
  20. model = BreadIngredient
  21. search_fields = ('name', )
  22. class BreadTypeAdmin(ModelAdmin):
  23. model = BreadType
  24. search_fields = ('title', )
  25. class BreadCountryAdmin(ModelAdmin):
  26. model = Country
  27. search_fields = ('title', )
  28. class BreadModelAdminGroup(ModelAdminGroup):
  29. menu_label = 'Bread Categories'
  30. menu_icon = 'fa-suitcase' # change as required
  31. menu_order = 200 # will put in 3rd place (000 being 1st, 100 2nd)
  32. items = (BreadIngredientAdmin, BreadTypeAdmin, BreadCountryAdmin)
  33. class PeopleModelAdmin(ModelAdmin):
  34. model = People
  35. menu_label = 'People' # ditch this to use verbose_name_plural from model
  36. menu_icon = 'fa-users' # change as required
  37. list_display = ('first_name', 'last_name', 'job_title', 'thumb_image')
  38. list_filter = ('job_title', )
  39. search_fields = ('first_name', 'last_name', 'job_title')
  40. inspect_view_enabled = True
  41. class FooterTextAdmin(ModelAdmin):
  42. model = FooterText
  43. search_fields = ('body',)
  44. class BakeryModelAdminGroup(ModelAdminGroup):
  45. menu_label = 'Bakery Misc'
  46. menu_icon = 'fa-cutlery' # change as required
  47. menu_order = 300 # will put in 4th place (000 being 1st, 100 2nd)
  48. items = (PeopleModelAdmin, FooterTextAdmin)
  49. # When using a ModelAdminGroup class to group several ModelAdmin classes together,
  50. # you only need to register the ModelAdminGroup class with Wagtail:
  51. modeladmin_register(BreadModelAdminGroup)
  52. modeladmin_register(BakeryModelAdminGroup)