From f79a45b470afaa5a12a3906ee648ffc76ba97aa8 Mon Sep 17 00:00:00 2001 From: Faheedkhan Date: Mon, 2 Jun 2025 17:04:35 +0300 Subject: [PATCH] check2 --- inventory/views.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/inventory/views.py b/inventory/views.py index efe9b285..6f448a08 100644 --- a/inventory/views.py +++ b/inventory/views.py @@ -951,6 +951,22 @@ class CarColorsUpdateView( LoginRequiredMixin, PermissionRequiredMixin, SuccessM template_name = "inventory/add_colors.html" success_message = _("Car finance details updated successfully") permission_required = ["inventory.change_carfinance"] + def get_object(self, queryset=None): + """ + Retrieves the CarColors instance associated with the Car slug from the URL. + This ensures we are updating the colors for the correct car. + """ + + # Get the car_slug from the URL keywords arguments + slug = self.kwargs.get('slug') + + # If no car_slug is provided, it's an invalid request + if not slug: + # You might want to raise Http404 or a more specific error here + raise ValueError("Car slug is required to identify the colors to update.") + + + return get_object_or_404(models.CarColors, car__slug=slug) def get_success_url(self): return reverse("car_detail", kwargs={"slug": self.object.car.slug})