[Answer]-Trouble setting up forms

1👍

You load the form with the data…

MyModelForm(instance=myInstanceModel)

You can make use of instance parameter to instantiate form which will put initial data in the form from that object, instead of providing dict of attributes.

another example

object = myModel.objects.get(id=1)
MyModelForm(instance=object)

0👍

You want to have a view to update your model, What you’re looking for is UpdateView

A view that displays a form for editing an existing object,
redisplaying the form with validation errors (if there are any) and
saving changes to the object. This uses a form automatically generated
from the object’s model class (unless a form class is manually
specified). — Django docs

Example:

from django.views.generic.edit import UpdateView
from myapp.models import Author

class AuthorUpdate(UpdateView):
    model = Author

These might be helpful too:

Leave a comment