diff --git a/sage_invoice/api/views/category.py b/sage_invoice/api/views/category.py index 31f4b49..fefd895 100644 --- a/sage_invoice/api/views/category.py +++ b/sage_invoice/api/views/category.py @@ -7,7 +7,7 @@ class CategoryViewSet(ErrorHandlingMixin, viewsets.ModelViewSet): - queryset = Category.objects.all() + queryset = Category.objects.prefetch_related("invoices").all() serializer_class = CategorySerializer lookup_field = "slug" diff --git a/sage_invoice/api/views/column.py b/sage_invoice/api/views/column.py index 02d4f03..f7cba7f 100644 --- a/sage_invoice/api/views/column.py +++ b/sage_invoice/api/views/column.py @@ -6,7 +6,7 @@ class ColumnViewSet(viewsets.ModelViewSet): - queryset = Column.objects.all() + queryset = Column.objects.select_related("invoice", "item").all() serializer_class = ColumnSerializer lookup_field = "id" lookup_url_kwarg = "id" diff --git a/sage_invoice/api/views/expense.py b/sage_invoice/api/views/expense.py index 202237f..ccd136c 100644 --- a/sage_invoice/api/views/expense.py +++ b/sage_invoice/api/views/expense.py @@ -6,7 +6,7 @@ class ExpenseViewSet(viewsets.ModelViewSet): - queryset = Expense.objects.all() + queryset = Expense.objects.select_related("invoice").all() serializer_class = ExpenseSerializer lookup_field = "id" lookup_url_kwarg = "id" diff --git a/sage_invoice/api/views/invoice.py b/sage_invoice/api/views/invoice.py index 9a76aa1..2495022 100644 --- a/sage_invoice/api/views/invoice.py +++ b/sage_invoice/api/views/invoice.py @@ -16,7 +16,9 @@ class InvoiceViewSet(ErrorHandlingMixin, viewsets.ModelViewSet): - queryset = Invoice.objects.all() + queryset = Invoice.objects.select_related("category", "expense", "customer").prefetch_related("category__invoices", + "items__invoice", "columns__item" + ).all() serializer_class = InvoiceSerializer lookup_field = "slug" versioning_class = HeaderVersioning diff --git a/sage_invoice/api/views/item.py b/sage_invoice/api/views/item.py index 3a52a40..e15efbe 100644 --- a/sage_invoice/api/views/item.py +++ b/sage_invoice/api/views/item.py @@ -6,7 +6,7 @@ class ItemViewSet(viewsets.ModelViewSet): - queryset = Item.objects.all() + queryset = Item.objects.select_related("invoice").all() serializer_class = ItemSerializer lookup_field = "id" lookup_url_kwarg = "id"