From 20715a195d1f8470ae05d654f82fbb0943858fb1 Mon Sep 17 00:00:00 2001 From: pablohashescobar Date: Mon, 31 Jul 2023 18:23:42 +0530 Subject: [PATCH] fix: project creation --- apiserver/plane/db/models/project.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/apiserver/plane/db/models/project.py b/apiserver/plane/db/models/project.py index f95a8c2f0..721b7b698 100644 --- a/apiserver/plane/db/models/project.py +++ b/apiserver/plane/db/models/project.py @@ -156,6 +156,20 @@ class ProjectMember(ProjectBaseModel): view_props = models.JSONField(default=get_default_props) default_props = models.JSONField(default=get_default_props) preferences = models.JSONField(default=get_default_preferences) + sort_order = models.FloatField(default=65535) + + + def save(self, *args, **kwargs): + if self._state.adding: + smallest_sort_order = ProjectMember.objects.filter( + workspace_id=self.workspace_id, member_id=self.member_id + ).aggregate(smallest=models.Min("sort_order"))["smallest"] + + # Project ordering + if smallest_sort_order is not None: + self.sort_order = smallest_sort_order - 10000 + + super(ProjectMember, self).save(*args, **kwargs) class Meta: unique_together = ["project", "member"]