M
M
maniacus262019-03-05 12:36:06
Django
maniacus26, 2019-03-05 12:36:06

Why does Django UpdateView reset values ​​to default after making a change?

Good afternoon!
There is a model in which there are fields

sent_adm = models.BooleanField(default=False)
sent_tmp = models.BooleanField(default=False)

There is a python script that, after certain conditions are met, sets the True value for one of the fields.
I look in the database (Postgresql), the value is True, I go into the Django project in the form that corresponds to the UpdateView in the view, change some value (not specified above) or just save the form, and the database fields described above become False again.
How can this happen?
class URDEditView(generic.UpdateView):
    model = URD
    fields = '__all__'

    def get_form(self, form_class=None):
        form = super().get_form(form_class)
        form.helper = FormHelper()
        form.helper.add_input(Submit('submit', 'Create', css_class='btn-primary'))

# ......  Куча аналогичных описаний полей
        

        form.fields['need_send_adm'].label = "отправить 1"
        form.fields['need_send_tmp'].label = "отправить 2"

        if form.is_valid():
            obj = form.save(commit=False)
            obj.author = self.request.user.username
            obj.save()
        return form

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question