Add start/end time fields to CalendarEvent (#28) (#29)
Unit Tests / test (push) Successful in 3s

## Summary
Closes #28.

- Add optional `start_time` / `end_time` (`TimeField`) on `CalendarEvent`
- Expose times in Django admin list + form
- Replace hardcoded calendar template times with `time_range_display`
- Add migration `0013` and unit coverage for time formatting

## Test plan
- [ ] `python manage.py migrate`
- [ ] `python manage.py test schasite.tests.CalendarEventTests`
- [ ] In admin, edit an event with start/end times and confirm calendar page shows them
- [ ] Confirm events without times hide the Time rowReviewed-on: #29
This commit was merged in pull request #29.
This commit is contained in:
2026-08-04 11:00:24 -07:00
parent 04c3ac913c
commit f37ff3e87b
6 changed files with 80 additions and 2 deletions
+15
View File
@@ -66,6 +66,8 @@ class CalendarEvent(TimeInfoBase):
event_name = models.CharField(max_length=256)
start_date = models.DateField(blank=True, null=True)
end_date = models.DateField(blank=True, null=True)
start_time = models.TimeField(blank=True, null=True)
end_time = models.TimeField(blank=True, null=True)
location_name = models.CharField(max_length=256, blank=True, null=True)
coordinator_email = models.EmailField(max_length=256, blank=True, null=True)
event_link_name = models.CharField(max_length=64, blank=True, null=True)
@@ -90,6 +92,19 @@ class CalendarEvent(TimeInfoBase):
def no_date(self):
return not self.has_date()
def time_range_display(self):
"""Format start/end times for templates, e.g. '11:00 AM - 3:00 PM'."""
from django.utils.formats import time_format
if not self.start_time and not self.end_time:
return ""
start = time_format(self.start_time, "g:i A") if self.start_time else ""
end = time_format(self.end_time, "g:i A") if self.end_time else ""
if start and end:
return f"{start} - {end}"
return start or end
class CalendarEventAddressModel(TimeInfoBase):
calendar_event = models.OneToOneField(CalendarEvent, on_delete=models.CASCADE)