S
S
serhiops2022-04-08 23:00:12
Django
serhiops, 2022-04-08 23:00:12

How to inform the user that he has successfully made changes?

I am using UpdateView to change the data. And when the changes are done, I want a message to be displayed on the main screen using messages.success(request, "message")
How can this be implemented in a class?

class ChangeComent(UpdateView):
    model = Coments
    template_name = "myshop/change_coment.html"
    fields = ("text",)
    success_url = reverse_lazy("index")
    pk_url_kwarg = "pk_coment"

    def get_form(self, *args, **kwargs):
        form = super(ChangeComent, self).get_form(*args, **kwargs)
        form.fields['text'].widget.attrs["class"] = "form-control"
        form.fields['text'].widget.attrs["rows"] = 5
        return form

    def get_context_data(self, **kwargs):
        context =  super(ChangeComent, self).get_context_data(**kwargs)
        context['categories'] = Category.objects.all()
        return context

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2022-04-09
@serhiops

e.g. override the form_valid method

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question