diff --git a/src/core/models/events.py b/src/core/models/events.py index d2dfb2f09fddac209126ded5a44ca1b94f9e15f8..ef18c9cc5797cdce3fa622ceea1ddc5c36580d95 100644 --- a/src/core/models/events.py +++ b/src/core/models/events.py @@ -695,6 +695,9 @@ class EventAttachment(models.Model): class EventParticipant(models.Model): + class Meta: + ordering = ['order'] + class Role(models.TextChoices): SPEAKER = 'speaker', _('EventParticipant__type-speaker') ANGEL = 'angel', _('EventParticipant__type-angel') @@ -710,6 +713,9 @@ class EventParticipant(models.Model): max_length=20, choices=Role.choices, default=Role.REGULAR, help_text=_('EventParticipant__role__help'), verbose_name=_('EventParticipant__role') ) + # Future TODO: evaluate https://pypi.org/project/django-sortedm2m/ but for now we just use a simple order field + order = models.PositiveIntegerField() + is_accepted = models.BooleanField(default=False, help_text=_('EventParticipant__is_accepted__help'), verbose_name=_('EventParticipant__is_accepted')) is_public = models.BooleanField(default=False, help_text=_('EventParticipant__is_public__help'), verbose_name=_('EventParticipant__is_public')) @@ -727,6 +733,10 @@ class EventParticipant(models.Model): except ConferenceMember.DoesNotExist: raise ValidationError(_('EventParticipant__must_be_conference_member')) + if self.order is None: # if 'order' is not explicitly set + last_order = EventParticipant.objects.filter(event=self.event).aggregate(models.Max('order')).get('order__max') + self.order = (last_order or 0) + 1 + def __str__(self): result = self.participant.username if self.role in [self.Role.SPEAKER, self.Role.ANGEL]: