diff --git a/api/__pycache__/urls.cpython-311.pyc b/api/__pycache__/urls.cpython-311.pyc index 2e159340..d7507793 100644 Binary files a/api/__pycache__/urls.cpython-311.pyc and b/api/__pycache__/urls.cpython-311.pyc differ diff --git a/api/__pycache__/views.cpython-311.pyc b/api/__pycache__/views.cpython-311.pyc index 670f4d26..94bc6f61 100644 Binary files a/api/__pycache__/views.cpython-311.pyc and b/api/__pycache__/views.cpython-311.pyc differ diff --git a/api/urls.py b/api/urls.py index a5713d5e..e10dc1ae 100644 --- a/api/urls.py +++ b/api/urls.py @@ -18,5 +18,6 @@ router.register(r'car-option-values', views.CarOptionValueViewSet) urlpatterns = [ path('', include(router.urls)), path('cars/vin/', views.CarVINViewSet.as_view(), name='car_vin'), + path("cars/", views.car_list, name="car-list"), path('login/', views.LoginView.as_view(), name='login'), ] diff --git a/api/views.py b/api/views.py index d0c03086..56de2c53 100644 --- a/api/views.py +++ b/api/views.py @@ -1,10 +1,14 @@ +from django.core.paginator import Paginator from django.db.models import Q +from django.http import JsonResponse from django.views.decorators.csrf import csrf_exempt from rest_framework import permissions, status, viewsets, generics from rest_framework.views import APIView from rest_framework.response import Response from django.contrib.auth import authenticate from django.shortcuts import render + +from inventory.utils import get_user_type from . import models, serializers from .services import get_car_data, get_from_cardatabase from rest_framework.authtoken.models import Token @@ -96,3 +100,28 @@ class CarOptionViewSet(viewsets.ModelViewSet): class CarOptionValueViewSet(viewsets.ModelViewSet): queryset = inventory_models.CarOptionValue.objects.all() serializer_class = serializers.CarOptionValueSerializer + + + +def car_list(request): + dealer = get_user_type(request) + page = request.GET.get("page", 1) + per_page = 10 + + cars = inventory_models.Car.objects.filter(dealer=dealer).values( + "vin", + "id_car_make__name", + "id_car_model__name", + "status" + ) + + paginator = Paginator(cars, per_page) + page_obj = paginator.get_page(page) + + return JsonResponse({ + "data": list(page_obj), # Convert QuerySet to list + "page": page_obj.number, # Current page number + "per_page": per_page, + "total_pages": paginator.num_pages, # Total pages + "total_items": paginator.count # Total records + }) \ No newline at end of file diff --git a/inventory/__pycache__/models.cpython-311.pyc b/inventory/__pycache__/models.cpython-311.pyc index 785bef3b..2b860c9b 100644 Binary files a/inventory/__pycache__/models.cpython-311.pyc and b/inventory/__pycache__/models.cpython-311.pyc differ diff --git a/inventory/__pycache__/services.cpython-311.pyc b/inventory/__pycache__/services.cpython-311.pyc index 5ff92b96..6a8886ee 100644 Binary files a/inventory/__pycache__/services.cpython-311.pyc and b/inventory/__pycache__/services.cpython-311.pyc differ diff --git a/inventory/__pycache__/urls.cpython-311.pyc b/inventory/__pycache__/urls.cpython-311.pyc index cfa14e6f..2e5d0ba3 100644 Binary files a/inventory/__pycache__/urls.cpython-311.pyc and b/inventory/__pycache__/urls.cpython-311.pyc differ diff --git a/inventory/__pycache__/utils.cpython-311.pyc b/inventory/__pycache__/utils.cpython-311.pyc index a8c7c1b2..1c8d967d 100644 Binary files a/inventory/__pycache__/utils.cpython-311.pyc and b/inventory/__pycache__/utils.cpython-311.pyc differ diff --git a/inventory/__pycache__/views.cpython-311.pyc b/inventory/__pycache__/views.cpython-311.pyc index d16f8d4f..7a5c78e5 100644 Binary files a/inventory/__pycache__/views.cpython-311.pyc and b/inventory/__pycache__/views.cpython-311.pyc differ diff --git a/inventory/views.py b/inventory/views.py index f1ef3346..6defc1ce 100644 --- a/inventory/views.py +++ b/inventory/views.py @@ -328,7 +328,7 @@ class HomeView(TemplateView): return context class TestView(TemplateView): - template_name = "test.html" + template_name = "inventory/cars_list_api.html" class AccountingDashboard(LoginRequiredMixin, TemplateView): @@ -4383,4 +4383,6 @@ def apply_search_filters(queryset, query): for field in model._meta.get_fields(): if hasattr(field, 'attname') and field.get_internal_type() in ["CharField", "TextField", "EmailField"]: search_filters |= Q(**{f"{field.name}__icontains": query}) - return queryset.filter(search_filters).distinct() \ No newline at end of file + return queryset.filter(search_filters).distinct() + + diff --git a/templates/inventory/car_list_view.html b/templates/inventory/car_list_view.html index 92b7bca9..d2c2aa26 100644 --- a/templates/inventory/car_list_view.html +++ b/templates/inventory/car_list_view.html @@ -29,6 +29,7 @@