M
M
MOV_UA2019-11-10 22:55:43
Django
MOV_UA, 2019-11-10 22:55:43

A new entry is not added to the ModelForm to display on the page. Query is being updated. I tried everything, I don't know :( How to update ModelForm?

new_query = Queryes.objects.create(
                    name=form_q.cleaned_data['name'],
                    ...
                )
                new_query.save()
                ppk = new_query.pk
                mdl = Queryes.objects.get(pk=ppk)
                update_form = QueryesForm(request.POST, instance=mdl)
                update_form.save()
                context['html_data'] = render_to_string('filter_msgs.html', request=request,
                                                        context={'form_q': update_form})

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dr. Bacon, 2019-11-11
@bacon

1. Why save the newly created object (it is already saved)?
2. What for the same object anew to get from a DB?
3. Why change it with the same data it was created with?
4. It is not clear from the question whether you need to create a new object or edit an old one, in the code you are doing a strange, twice the same action, but in different ways.
Conclusion: complete misunderstanding of what you are doing.
Treatment: go through the django tutorial again or read the documentation thoughtfully.

M
MOV_UA, 2019-11-17
@MOV_UA

Model Form has a field that is f(field1, field) it is not recalculated when a new record is made

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question