0

I really don't understand what I'm doing wrong.

I am trying to create a view in which it will be possible to update information about the model object. I do this using UpdateView and ModelForm.

Here is the form that inherits objects from the model

class UpdateOrderDir(forms.ModelForm):

    class Meta:
        model = m.OrderStorage
        fields = '__all__'

HTML

<form action="" method="post">
    {% csrf_token %}
    {{ form.as_p }}
    <button type="submit">Save</button>
</form>

View

class DetailOrderViewDir(UpdateView):
    success_url = reverse_lazy('directorOrdersDetail')
    template_name = "director/order_detail_dir.html"
    form_class = f.UpdateOrderDir

    def get_queryset(self):
        return m.OrderStorage.objects.filter(pk=self.kwargs['pk'])

URL

path('director/orders/<int:pk>/', v.DetailOrderViewDir.as_view(), name='directorOrdersDetail'),

At the output I get a form.

enter image description here

When I make changes to the Form, the following error occurs, but the data is updated.

enter image description here

So that when submitting the form, the page is updated and the user is on the same page

num3ri
  • 822
  • 16
  • 20
mrrapi
  • 3
  • 2

1 Answers1

0

I solved the problem by passing success_url through a function.

    def get_success_url(self):
    return reverse_lazy('directorOrdersDetail', kwargs={'pk': self.kwargs['pk']}
mrrapi
  • 3
  • 2