Skip to content
Snippets Groups Projects
Commit 5c01e31f authored by Andreas Hubel's avatar Andreas Hubel
Browse files

feat: add order to EventParticipant (draft)

parent 3ee16cd0
No related branches found
No related tags found
No related merge requests found
......@@ -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]:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment