added the color update
This commit is contained in:
parent
f79a45b470
commit
a430a7ffd9
@ -945,12 +945,16 @@ class CarColorCreate(LoginRequiredMixin, PermissionRequiredMixin, CreateView):
|
|||||||
context["car"] = get_object_or_404(models.Car, slug=self.kwargs["slug"])
|
context["car"] = get_object_or_404(models.Car, slug=self.kwargs["slug"])
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class CarColorsUpdateView( LoginRequiredMixin, PermissionRequiredMixin, SuccessMessageMixin, UpdateView):
|
class CarColorsUpdateView( LoginRequiredMixin, PermissionRequiredMixin, SuccessMessageMixin, UpdateView):
|
||||||
model = models.CarColors
|
model = models.CarColors
|
||||||
form_class = forms.CarColorsForm
|
form_class = forms.CarColorsForm
|
||||||
template_name = "inventory/add_colors.html"
|
template_name = "inventory/add_colors.html"
|
||||||
success_message = _("Car finance details updated successfully")
|
success_message = _("Car Colors details updated successfully")
|
||||||
permission_required = ["inventory.change_carfinance"]
|
permission_required = ["inventory.change_car"]
|
||||||
|
|
||||||
|
|
||||||
def get_object(self, queryset=None):
|
def get_object(self, queryset=None):
|
||||||
"""
|
"""
|
||||||
Retrieves the CarColors instance associated with the Car slug from the URL.
|
Retrieves the CarColors instance associated with the Car slug from the URL.
|
||||||
@ -969,29 +973,22 @@ class CarColorsUpdateView( LoginRequiredMixin, PermissionRequiredMixin, SuccessM
|
|||||||
return get_object_or_404(models.CarColors, car__slug=slug)
|
return get_object_or_404(models.CarColors, car__slug=slug)
|
||||||
|
|
||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
|
"""
|
||||||
|
Redirects to the car's detail page using its slug after a successful update.
|
||||||
|
"""
|
||||||
|
# self.object refers to the CarColors instance that was just updated.
|
||||||
|
# self.object.car then refers to the associated Car instance.
|
||||||
return reverse("car_detail", kwargs={"slug": self.object.car.slug})
|
return reverse("car_detail", kwargs={"slug": self.object.car.slug})
|
||||||
|
|
||||||
def get_form_kwargs(self):
|
def get_context_data(self, **kwargs):
|
||||||
kwargs = super().get_form_kwargs()
|
"""
|
||||||
kwargs["instance"] = self.get_object()
|
Adds the related Car object to the template context.
|
||||||
return kwargs
|
"""
|
||||||
|
context = super().get_context_data(**kwargs)
|
||||||
def get_initial(self):
|
# self.object is already available here from get_object()
|
||||||
initial = super().get_initial()
|
context['car'] = self.object.car
|
||||||
instance = self.get_object()
|
context['page_title'] = _("Update Colors for %(car_name)s") % {'car_name': context['car']}
|
||||||
dealer = get_user_type(self.request)
|
return context
|
||||||
selected_items = instance.additional_services.filter(dealer=dealer)
|
|
||||||
initial["additional_finances"] = selected_items
|
|
||||||
return initial
|
|
||||||
|
|
||||||
def get_form(self, form_class=None):
|
|
||||||
form = super().get_form(form_class)
|
|
||||||
dealer = get_user_type(self.request)
|
|
||||||
form.fields[
|
|
||||||
"additional_finances"
|
|
||||||
].queryset = models.AdditionalServices.objects.filter(dealer=dealer)
|
|
||||||
return form
|
|
||||||
|
|
||||||
|
|
||||||
class CarListView(LoginRequiredMixin, PermissionRequiredMixin, ListView):
|
class CarListView(LoginRequiredMixin, PermissionRequiredMixin, ListView):
|
||||||
"""
|
"""
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user