feat(models.py): add max_attendees and signed_up_users fields to EventPage

This commit is contained in:
2026-03-16 12:26:08 +01:00
parent b637224eb5
commit dddf5cf70d

View File

@@ -85,6 +85,11 @@ class EventPage(Page):
# TODO: use google maps here # TODO: use google maps here
location = models.CharField(max_length=255, blank=True) location = models.CharField(max_length=255, blank=True)
max_attendees = models.PositiveIntegerField(
null=True,
blank=True,
help_text="Maximum number of attendees. Leave blank for unlimited.",
)
description = RichTextField(blank=True) description = RichTextField(blank=True)
hosts = ParentalManyToManyField( hosts = ParentalManyToManyField(
@@ -92,12 +97,35 @@ class EventPage(Page):
related_name="hosted_events", related_name="hosted_events",
help_text="Select users who will be listed as hosts of this event.", help_text="Select users who will be listed as hosts of this event.",
) )
signed_up_users = models.ManyToManyField(
User,
related_name="signed_up_events",
blank=True,
help_text="Users who have signed up for this event.",
)
@property
def attendees_count(self):
return self.signed_up_users.count() # pyright: ignore[reportAttributeAccessIssue]
def _user_signed_up(self, user):
if not user.is_authenticated:
return False
return self.signed_up_users.filter(id__in=[user.id]).exists() # pyright: ignore[reportAttributeAccessIssue]
def get_context(self, request):
context = super().get_context(request)
context["user_signed_up"] = self._user_signed_up(request.user)
return context
content_panels = Page.content_panels + [ content_panels = Page.content_panels + [
FieldPanel("image"), FieldPanel("image"),
FieldPanel("start"), FieldPanel("start"),
FieldPanel("end"), FieldPanel("end"),
FieldPanel("location"), FieldPanel("location"),
FieldPanel("max_attendees"),
FieldPanel("hosts", widget=CheckboxSelectMultiple), FieldPanel("hosts", widget=CheckboxSelectMultiple),
FieldPanel("description"), FieldPanel("description"),
FieldPanel("signed_up_users", read_only=True, widget=CheckboxSelectMultiple),
] ]