models.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. from __future__ import unicode_literals
  2. from django.db import models
  3. from wagtail.wagtailcore.models import Page, Orderable, Collection
  4. from wagtail.wagtailsearch import index
  5. from wagtail.wagtailimages.edit_handlers import ImageChooserPanel
  6. from wagtail.wagtailcore.fields import StreamField
  7. from wagtail.wagtailadmin.edit_handlers import (
  8. FieldPanel, InlinePanel, FieldRowPanel, StreamFieldPanel)
  9. from wagtail.wagtailsnippets.models import register_snippet
  10. from wagtail.wagtailsnippets.edit_handlers import SnippetChooserPanel
  11. from blocks import BaseStreamBlock
  12. @register_snippet
  13. class People(models.Model):
  14. first_name = models.CharField("First name", max_length=254)
  15. last_name = models.CharField("Last name", max_length=254)
  16. job_title = models.CharField("Job title", max_length=254)
  17. image = models.ForeignKey(
  18. 'wagtailimages.Image',
  19. null=True,
  20. blank=True,
  21. on_delete=models.SET_NULL,
  22. related_name='+'
  23. )
  24. panels = [
  25. FieldPanel('first_name', classname="col6"),
  26. FieldPanel('last_name', classname="col6"),
  27. FieldPanel('job_title'),
  28. ImageChooserPanel('image')
  29. ]
  30. def __str__(self):
  31. return self.first_name + " " + self.last_name
  32. class Meta:
  33. verbose_name = 'Person'
  34. verbose_name_plural = 'People'
  35. # class AboutLocationRelationship(Orderable, models.Model):
  36. # """
  37. # This defines the relationship between the `LocationPage` within the `locations`
  38. # app and the About page below allowing us to add locations to the about
  39. # section.
  40. # """
  41. # about = ParentalKey(
  42. # 'About', related_name='location_about_relationship'
  43. # )
  44. # locations = models.ForeignKey(
  45. # 'locations.LocationPage', related_name='about_location_relationship'
  46. # )
  47. # panels = [
  48. # PageChooserPanel('locations')
  49. # ]
  50. class AboutPage(Page):
  51. """
  52. The About Page
  53. """
  54. image = models.ForeignKey(
  55. 'wagtailimages.Image',
  56. null=True,
  57. blank=True,
  58. on_delete=models.SET_NULL,
  59. related_name='+',
  60. help_text='Location image'
  61. )
  62. body = StreamField(
  63. BaseStreamBlock(), verbose_name="About page detail", blank=True
  64. )
  65. # We've defined the StreamBlock() within blocks.py that we've imported on
  66. # line 12. Defining it in a different file gives us consistency across the
  67. # site, though StreamFields _can_ be created on a per model basis if you
  68. # have a use case for it
  69. content_panels = Page.content_panels + [
  70. ImageChooserPanel('image'),
  71. StreamFieldPanel('body'),
  72. # InlinePanel(
  73. # 'about_location_relationship',
  74. # label='Locations',
  75. # min_num=None
  76. # ),
  77. ]
  78. # parent_page_types = [
  79. # 'home.HomePage'
  80. # ]
  81. # Defining what content type can sit under the parent
  82. # The empty array means that no children can be placed under the
  83. # LocationPage page model
  84. subpage_types = []
  85. # api_fields = ['image', 'body']
  86. def getImageCollections():
  87. # We return all collections to a list that don't have the name root.
  88. return [(
  89. collection.id, collection.name
  90. ) for collection in Collection.objects.all().exclude(
  91. name='Root'
  92. )]
  93. class GalleryPage(Page):
  94. """
  95. This is a page to list all the locations on the site
  96. """
  97. CHOICES_LIST = getImageCollections()
  98. # To return our collection choices for the editor to access we need to
  99. # make the choices list a variable rather than a function
  100. choices = models.CharField(
  101. max_length=255, choices=CHOICES_LIST
  102. )
  103. image = models.ForeignKey(
  104. 'wagtailimages.Image',
  105. null=True,
  106. blank=True,
  107. on_delete=models.SET_NULL,
  108. related_name='+',
  109. help_text='Location listing image'
  110. )
  111. introduction = models.TextField(
  112. help_text='Text to describe the index page',
  113. blank=True)
  114. content_panels = Page.content_panels + [
  115. FieldPanel('choices'),
  116. ImageChooserPanel('image'),
  117. FieldPanel('introduction')
  118. ]
  119. # parent_page_types = [
  120. # 'home.HomePage'
  121. # ]
  122. # Defining what content type can sit under the parent. Since it's a blank
  123. # array no subpage can be added
  124. subpage_types = [
  125. ]
  126. # api_fields = ['introduction']