models.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. from django.db import models
  2. from modelcluster.fields import ParentalKey
  3. from wagtail.admin.panels import FieldPanel, InlinePanel, MultiFieldPanel
  4. from wagtail.fields import StreamField
  5. from wagtail.models import Orderable, Page
  6. from .blocks import BLOCKS
  7. class RecipePage(Page):
  8. """
  9. RecipePage, to illustrate some Recipe Wagtail scenario's
  10. """
  11. title_1 = models.CharField(max_length=255, default="Title 1")
  12. section_1 = StreamField(
  13. BLOCKS,
  14. blank=True,
  15. use_json_field=True,
  16. help_text="Section 1 is a StreamField in a regular FieldPanel",
  17. )
  18. title_2 = models.CharField(max_length=255, default="Title 2")
  19. section_2 = StreamField(
  20. BLOCKS,
  21. blank=True,
  22. use_json_field=True,
  23. help_text="Section 2 is a StreamField in a MultiFieldPanel",
  24. )
  25. content_panels = Page.content_panels + [
  26. FieldPanel("title_1"),
  27. FieldPanel("section_1"),
  28. MultiFieldPanel(
  29. [
  30. FieldPanel("title_2"),
  31. FieldPanel("section_2"),
  32. ],
  33. heading="MultiFieldPanel for section 2",
  34. ),
  35. InlinePanel(
  36. "items", label="Items", help_text="Related items via an inline panel"
  37. ),
  38. ]
  39. class Item(Orderable):
  40. page = ParentalKey(RecipePage, on_delete=models.CASCADE, related_name="items")
  41. title_1 = models.CharField(max_length=255, default="Title 1")
  42. section_1 = StreamField(
  43. BLOCKS,
  44. blank=True,
  45. use_json_field=True,
  46. help_text="Section 1 is a StreamField in a regular FieldPanel",
  47. )
  48. title_2 = models.CharField(max_length=255, default="Title 2")
  49. section_2 = StreamField(
  50. BLOCKS,
  51. blank=True,
  52. use_json_field=True,
  53. help_text="Section 2 is a StreamField in a MultiFieldPanel",
  54. )
  55. panels = [
  56. FieldPanel("title_1"),
  57. FieldPanel("section_1"),
  58. MultiFieldPanel(
  59. [
  60. FieldPanel("title_2"),
  61. FieldPanel("section_2"),
  62. ],
  63. heading="MultiFieldPanel for section 2",
  64. ),
  65. ]