From ff493dc03d1740cd6be257663021563aacde5229 Mon Sep 17 00:00:00 2001 From: behruz-dev Date: Thu, 7 Aug 2025 15:09:26 +0500 Subject: [PATCH] add is_archive field on project --- .../migrations/0012_project_is_archive.py | 18 ++++++++++++++++++ core/apps/projects/models/project.py | 1 + core/apps/projects/urls.py | 1 + core/apps/projects/views/project.py | 19 +++++++++++++++++-- 4 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 core/apps/projects/migrations/0012_project_is_archive.py diff --git a/core/apps/projects/migrations/0012_project_is_archive.py b/core/apps/projects/migrations/0012_project_is_archive.py new file mode 100644 index 0000000..38b4031 --- /dev/null +++ b/core/apps/projects/migrations/0012_project_is_archive.py @@ -0,0 +1,18 @@ +# Generated by Django 5.2.4 on 2025-08-07 15:07 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('projects', '0011_alter_project_location'), + ] + + operations = [ + migrations.AddField( + model_name='project', + name='is_archive', + field=models.BooleanField(default=False), + ), + ] diff --git a/core/apps/projects/models/project.py b/core/apps/projects/models/project.py index a84d466..ce2a252 100644 --- a/core/apps/projects/models/project.py +++ b/core/apps/projects/models/project.py @@ -81,6 +81,7 @@ class Project(BaseModel): currency = models.CharField(choices=[('usd', 'usd'),('uzs','uzs')], max_length=3, default='uzs') benifit_plan = models.PositiveBigIntegerField(null=True) status = models.CharField(max_length=20, choices=STATUS, default='PLANNED') + is_archive = models.BooleanField(default=False) def __str__(self): return self.name diff --git a/core/apps/projects/urls.py b/core/apps/projects/urls.py index 7fe0bf7..24b0308 100644 --- a/core/apps/projects/urls.py +++ b/core/apps/projects/urls.py @@ -12,6 +12,7 @@ urlpatterns = [ path('/update/', project_views.ProjectUpdateApiView.as_view()), path('/delete/', project_views.ProjectDeleteApiView.as_view()), path('change_folder/', project_views.ChangeProjectFolderApiView.as_view()), + path('archive//', project_views.ArchiveProjectApiView.as_view()), ] )), path('project_folder/', include( diff --git a/core/apps/projects/views/project.py b/core/apps/projects/views/project.py index 9306cb3..a955078 100644 --- a/core/apps/projects/views/project.py +++ b/core/apps/projects/views/project.py @@ -1,4 +1,5 @@ from django.shortcuts import get_object_or_404 +from django.db.models import Prefetch from rest_framework import generics, status, views from rest_framework.response import Response @@ -11,7 +12,7 @@ from core.apps.shared.paginations.custom import CustomPageNumberPagination class ProjectListApiView(generics.ListAPIView): serializer_class = serializers.ProjectListSerializer - queryset = Project.objects.select_related('location') + queryset = Project.objects.filter(is_archive=False).select_related('location') permission_classes = [HasRolePermission] required_permissions = ['project'] pagination_class = CustomPageNumberPagination @@ -50,6 +51,18 @@ class ProjectDeleteApiView(generics.DestroyAPIView): queryset = Project.objects.all() +class ArchiveProjectApiView(generics.GenericAPIView): + serializer_class = None + permission_classes = [HasRolePermission] + required_permissions = ['project'] + + def get(self, request, id): + project = get_object_or_404(Project, id=id) + project.is_archive = True + project.save() + return Response({"success": True, "message": "Archived"}, status=200) + + # Project Folder class ProjectFolderCreateApiView(generics.CreateAPIView): serializer_class = serializers.ProjectFolderCreateSerializer @@ -60,7 +73,9 @@ class ProjectFolderCreateApiView(generics.CreateAPIView): class ProjectFolderListApiView(generics.ListAPIView): serializer_class = serializers.ProjectFolderListSerializer - queryset = ProjectFolder.objects.prefetch_related('projects') + queryset = ProjectFolder.objects.prefetch_related( + Prefetch('projects', Project.objects.filter(is_archive=False)) + ) permission_classes = [HasRolePermission] required_permissions = ['project_folder'] pagination_class = CustomPageNumberPagination