mirror of
https://github.com/inventree/InvenTree.git
synced 2025-12-16 17:28:11 +00:00
Refactoring some code
This commit is contained in:
@@ -37,7 +37,21 @@ from .serializers import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class CompanyList(DataExportViewMixin, ListCreateAPI):
|
class CompanyMixin(OutputOptionsMixin):
|
||||||
|
"""Mixin class for Company API endpoints."""
|
||||||
|
|
||||||
|
queryset = Company.objects.all()
|
||||||
|
serializer_class = CompanySerializer
|
||||||
|
|
||||||
|
def get_queryset(self):
|
||||||
|
"""Return annotated queryset for the company endpoints."""
|
||||||
|
queryset = super().get_queryset()
|
||||||
|
queryset = CompanySerializer.annotate_queryset(queryset)
|
||||||
|
|
||||||
|
return queryset
|
||||||
|
|
||||||
|
|
||||||
|
class CompanyList(CompanyMixin, DataExportViewMixin, ListCreateAPI):
|
||||||
"""API endpoint for accessing a list of Company objects.
|
"""API endpoint for accessing a list of Company objects.
|
||||||
|
|
||||||
Provides two methods:
|
Provides two methods:
|
||||||
@@ -46,14 +60,6 @@ class CompanyList(DataExportViewMixin, ListCreateAPI):
|
|||||||
- POST: Create a new Company object
|
- POST: Create a new Company object
|
||||||
"""
|
"""
|
||||||
|
|
||||||
serializer_class = CompanySerializer
|
|
||||||
queryset = Company.objects.all()
|
|
||||||
|
|
||||||
def get_queryset(self):
|
|
||||||
"""Return annotated queryset for the company list endpoint."""
|
|
||||||
queryset = super().get_queryset()
|
|
||||||
return CompanySerializer.annotate_queryset(queryset)
|
|
||||||
|
|
||||||
filter_backends = SEARCH_ORDER_FILTER
|
filter_backends = SEARCH_ORDER_FILTER
|
||||||
|
|
||||||
filterset_fields = [
|
filterset_fields = [
|
||||||
@@ -71,19 +77,9 @@ class CompanyList(DataExportViewMixin, ListCreateAPI):
|
|||||||
ordering = 'name'
|
ordering = 'name'
|
||||||
|
|
||||||
|
|
||||||
class CompanyDetail(RetrieveUpdateDestroyAPI):
|
class CompanyDetail(CompanyMixin, RetrieveUpdateDestroyAPI):
|
||||||
"""API endpoint for detail of a single Company object."""
|
"""API endpoint for detail of a single Company object."""
|
||||||
|
|
||||||
queryset = Company.objects.all()
|
|
||||||
serializer_class = CompanySerializer
|
|
||||||
|
|
||||||
def get_queryset(self):
|
|
||||||
"""Return annotated queryset for the company detail endpoint."""
|
|
||||||
queryset = super().get_queryset()
|
|
||||||
queryset = CompanySerializer.annotate_queryset(queryset)
|
|
||||||
|
|
||||||
return queryset
|
|
||||||
|
|
||||||
|
|
||||||
class ContactList(DataExportViewMixin, ListCreateDestroyAPIView):
|
class ContactList(DataExportViewMixin, ListCreateDestroyAPIView):
|
||||||
"""API endpoint for list view of Company model."""
|
"""API endpoint for list view of Company model."""
|
||||||
|
|||||||
Reference in New Issue
Block a user