[Answer]-Django – having trouble saving filtered object

1👍

There is, of course, a way to only use some fields in a modelform: as fully documented in Using a subset of fields on the form, you can use the fields or exclude attributes in the form’s Meta class.

However you’ll still need, as szaman points out, to pass the POST data to the form and check for validity, and in addition you’ll need to pass in the instance paramater as you’re updating an existing instance.

0👍

What I see is that you get object from database and when form is submitted than just saving the object, but you don’t update any field so you cannot see changes in db. Try to do:

if request.method == "POST":
        form = MyForm(request.POST)
        logging.info("form.is_valid() %s" % form.is_valid())
        if form.is_valid():
            item_to_edit.name = form.cleaned_data['name']
            item_to_edit.save()
...
👤szaman

Leave a comment