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})