add is_archive field on project

This commit is contained in:
behruz-dev
2025-08-07 15:09:26 +05:00
parent e018be4447
commit ff493dc03d
4 changed files with 37 additions and 2 deletions

View File

@@ -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),
),
]

View File

@@ -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

View File

@@ -12,6 +12,7 @@ urlpatterns = [
path('<uuid:id>/update/', project_views.ProjectUpdateApiView.as_view()),
path('<uuid:id>/delete/', project_views.ProjectDeleteApiView.as_view()),
path('change_folder/', project_views.ChangeProjectFolderApiView.as_view()),
path('archive/<uuid:id>/', project_views.ArchiveProjectApiView.as_view()),
]
)),
path('project_folder/', include(

View File

@@ -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