add is_archive field on project
This commit is contained in:
18
core/apps/projects/migrations/0012_project_is_archive.py
Normal file
18
core/apps/projects/migrations/0012_project_is_archive.py
Normal 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),
|
||||
),
|
||||
]
|
||||
@@ -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
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user