forked from github/plane
feat: project ordering (#1701)
* dev: project ordering * dev: add ordering for projects list
This commit is contained in:
parent
c98edd4a91
commit
8e0124be91
@ -123,7 +123,7 @@ class ProjectViewSet(BaseViewSet):
|
||||
projects = (
|
||||
self.get_queryset()
|
||||
.annotate(is_favorite=Exists(subquery))
|
||||
.order_by("-is_favorite", "name")
|
||||
.order_by("sort_order", "name")
|
||||
.annotate(
|
||||
total_members=ProjectMember.objects.filter(
|
||||
project_id=OuterRef("id")
|
||||
|
@ -1,5 +1,5 @@
|
||||
# Generated by Django 4.2.3 on 2023-07-23 16:33
|
||||
|
||||
import random
|
||||
from django.db import migrations, models
|
||||
import plane.db.models.workspace
|
||||
|
||||
@ -58,6 +58,18 @@ def update_workspace_member_props(apps, schema_editor):
|
||||
Model.objects.bulk_update(updated_workspace_member, ["view_props"], batch_size=100)
|
||||
|
||||
|
||||
def update_project_sort_order(apps, schema_editor):
|
||||
Model = apps.get_model("db", "Project")
|
||||
|
||||
updated_projects = []
|
||||
|
||||
for obj in Model.objects.all():
|
||||
obj.sort_order = random.randint(1, 65536)
|
||||
updated_projects.append(obj)
|
||||
|
||||
Model.objects.bulk_update(updated_projects, ["sort_order"], batch_size=100)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("db", "0038_auto_20230720_1505"),
|
||||
@ -76,4 +88,10 @@ class Migration(migrations.Migration):
|
||||
name='default_props',
|
||||
field=models.JSONField(default=plane.db.models.workspace.get_default_props),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='project',
|
||||
name='sort_order',
|
||||
field=models.FloatField(default=65535),
|
||||
),
|
||||
migrations.RunPython(update_project_sort_order),
|
||||
]
|
||||
|
@ -91,6 +91,7 @@ class Project(BaseModel):
|
||||
default_state = models.ForeignKey(
|
||||
"db.State", on_delete=models.SET_NULL, null=True, related_name="default_state"
|
||||
)
|
||||
sort_order = models.FloatField(default=65535)
|
||||
|
||||
def __str__(self):
|
||||
"""Return name of the project"""
|
||||
|
Loading…
Reference in New Issue
Block a user