order permissions

This commit is contained in:
2025-07-07 10:16:05 +03:30
parent 9a9b55dd28
commit 3035b0c84a
2 changed files with 21 additions and 1 deletions

View File

@@ -66,6 +66,17 @@ class PermissionViewSet(viewsets.ModelViewSet):
filter_backends = [filters.SearchFilter] filter_backends = [filters.SearchFilter]
search_fields = ['page__name', ] search_fields = ['page__name', ]
def list(self, request, *args, **kwargs):
queryset = self.filter_queryset(self.get_queryset().order_by('-create_date')) # noqa
page = self.paginate_queryset(queryset)
if page is not None:
serializer = self.get_serializer(page, many=True)
return self.get_paginated_response(serializer.data)
serializer = self.get_serializer(queryset, many=True)
return Response(serializer.data)
def create(self, request, *args, **kwargs): def create(self, request, *args, **kwargs):
if self.queryset.filter(name=request.data['name'], page_id=request.data['page']).exists(): if self.queryset.filter(name=request.data['name'], page_id=request.data['page']).exists():
raise ConflictException('a permission with this page exists.') raise ConflictException('a permission with this page exists.')

View File

@@ -112,7 +112,16 @@ class Product(BaseModel):
quota__is_closed=False quota__is_closed=False
).aggregate(total_entry=models.Sum('warehouse_entry'))['total_entry'] or 0 ).aggregate(total_entry=models.Sum('warehouse_entry'))['total_entry'] or 0
return {'quotas_count': quotas_count, 'total_quotas_weight': total_quotas_weight} data = {
'quotas_count': quotas_count,
'total_quotas_weight': total_quotas_weight,
'total_remaining_quotas_weight': total_remaining_quotas_weight,
'total_distributed_weight': total_distributed_weight,
'total_sold': total_sold,
'total_warehouse_entry': total_warehouse_entry,
}
return data
def __str__(self): def __str__(self):
return f'name: {self.name} - type: {self.type}' return f'name: {self.name} - type: {self.type}'