2
0

models.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. from django.db import models
  2. from modelcluster.fields import ParentalKey
  3. from wagtail.wagtailadmin.edit_handlers import FieldPanel, InlinePanel
  4. from wagtail.wagtailcore.models import Orderable, Page
  5. from wagtail.wagtailimages.edit_handlers import ImageChooserPanel
  6. from wagtail.wagtailsearch import index
  7. class OperatingHours(models.Model):
  8. '''
  9. Django model to capture operating hours for a Location
  10. '''
  11. MONDAY = 'MON'
  12. TUESDAY = 'TUE'
  13. WEDNESDAY = 'WED'
  14. THURSDAY = 'THU'
  15. FRIDAY = 'FRI'
  16. SATURDAY = 'SAT'
  17. SUNDAY = 'SUN'
  18. DAY_CHOICES = (
  19. (MONDAY, 'MON'),
  20. (TUESDAY, 'TUE'),
  21. (WEDNESDAY, 'WED'),
  22. (THURSDAY, 'THU'),
  23. (FRIDAY, 'FRI'),
  24. (SATURDAY, 'SAT'),
  25. (SUNDAY, 'SUN'),
  26. )
  27. day = models.CharField(
  28. max_length=3,
  29. choices=DAY_CHOICES,
  30. default=MONDAY,
  31. )
  32. opening_time = models.TimeField()
  33. closing_time = models.TimeField()
  34. panels = [
  35. FieldPanel('day'),
  36. FieldPanel('opening_time'),
  37. FieldPanel('closing_time'),
  38. ]
  39. class Meta:
  40. abstract = True
  41. def __str__(self):
  42. return '{}: {} - {}'.format(self.day, self.opening_time, self.closing_time)
  43. class LocationOperatingHours(Orderable, OperatingHours):
  44. '''
  45. Operating Hours entry for a Location
  46. '''
  47. location = ParentalKey(
  48. 'LocationPage',
  49. related_name='hours_of_operation'
  50. )
  51. class LocationsLandingPage(Page):
  52. '''
  53. Home page for locations
  54. '''
  55. pass
  56. class LocationPage(Page):
  57. '''
  58. Detail for a specific location
  59. '''
  60. address = models.TextField()
  61. image = models.ForeignKey(
  62. 'wagtailimages.Image',
  63. null=True,
  64. blank=True,
  65. on_delete=models.SET_NULL,
  66. related_name='+'
  67. )
  68. lat_long = models.CharField(
  69. max_length=36,
  70. help_text="Comma separated lat/long. (Ex. 64.144367, -21.939182) \
  71. Right click Google Maps and click 'What\'s Here'"
  72. )
  73. # Search index configuration
  74. search_fields = Page.search_fields + [
  75. index.SearchField('address'),
  76. ]
  77. # Editor panels configuration
  78. content_panels = Page.content_panels + [
  79. FieldPanel('address', classname="full"),
  80. FieldPanel('lat_long'),
  81. ImageChooserPanel('image'),
  82. InlinePanel('hours_of_operation', label="Hours of Operation")
  83. ]
  84. def __str__(self):
  85. return self.name