Add initial implementations for forms and organization apps with serializers, factories, and admin configurations
Some checks failed
CI/CD Pipeline / Code Quality Checks (push) Failing after 5m5s
CI/CD Pipeline / Run Tests (push) Failing after 5m5s
CI/CD Pipeline / Build Docker Images (push) Has been skipped
CI/CD Pipeline / Push to Gitea Registry (push) Has been skipped
CI/CD Pipeline / Deploy to Server (push) Has been skipped
Some checks failed
CI/CD Pipeline / Code Quality Checks (push) Failing after 5m5s
CI/CD Pipeline / Run Tests (push) Failing after 5m5s
CI/CD Pipeline / Build Docker Images (push) Has been skipped
CI/CD Pipeline / Push to Gitea Registry (push) Has been skipped
CI/CD Pipeline / Deploy to Server (push) Has been skipped
This commit is contained in:
57
src/apps/organization/api.py
Normal file
57
src/apps/organization/api.py
Normal file
@@ -0,0 +1,57 @@
|
||||
"""
|
||||
API ViewSets для организаций.
|
||||
|
||||
Содержит:
|
||||
- OrganizationViewSet - CRUD для организаций
|
||||
"""
|
||||
|
||||
from apps.core.viewsets import ReadOnlyViewSet
|
||||
from apps.organization.models import Organization
|
||||
from apps.organization.serializers import (
|
||||
OrganizationListSerializer,
|
||||
OrganizationSerializer,
|
||||
)
|
||||
from django_filters import rest_framework as filters
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
|
||||
|
||||
class OrganizationFilter(filters.FilterSet):
|
||||
"""Фильтры для организаций."""
|
||||
|
||||
name = filters.CharFilter(lookup_expr="icontains")
|
||||
inn = filters.CharFilter(lookup_expr="exact")
|
||||
ogrn = filters.CharFilter(lookup_expr="exact")
|
||||
|
||||
class Meta:
|
||||
model = Organization
|
||||
fields = ["name", "inn", "ogrn"]
|
||||
|
||||
|
||||
class OrganizationViewSet(ReadOnlyViewSet[Organization]):
|
||||
"""
|
||||
ViewSet для просмотра организаций.
|
||||
|
||||
Только чтение - организации создаются автоматически при загрузке форм.
|
||||
|
||||
Эндпоинты:
|
||||
GET /organizations/ - список организаций
|
||||
GET /organizations/{id}/ - детали организации
|
||||
"""
|
||||
|
||||
queryset = Organization.objects.all()
|
||||
serializer_class = OrganizationSerializer
|
||||
permission_classes = [IsAuthenticated]
|
||||
filterset_class = OrganizationFilter
|
||||
search_fields = ["name", "inn", "ogrn"]
|
||||
ordering_fields = ["name", "inn", "created_at"]
|
||||
ordering = ["name"]
|
||||
|
||||
serializer_classes = {
|
||||
"list": OrganizationListSerializer,
|
||||
}
|
||||
|
||||
def get_serializer_class(self):
|
||||
"""Возвращает serializer в зависимости от action."""
|
||||
if self.action in self.serializer_classes:
|
||||
return self.serializer_classes[self.action]
|
||||
return super().get_serializer_class()
|
||||
Reference in New Issue
Block a user