Q:

Django: How to use modal as a form to update an object

I'm trying to use modal as a edit form but I don't know good way.
Currently my views.py is like this.
def edit_entry(request, entry_pk):

    entry = get_object_or_404(Entry, pk=entry_pk)

    if request.method != 'POST':
        form = EntryForm(instance=entry, user=request.user)
    else:
       form = EntryForm(instance=entry, data=request.POST, user=request.user)

        if form.is_valid():
            form.save()

and I have a template for this view.
What I want to do is
from the page that lists a bunch of entry objects, the edit form for the object is shown when I click edit button.
{% for entry in entries %}
    ...
    <button class="btn btn-outline-primary" data-toggle="modal" data-target="#editEntryModal">Edit</button>

    <!-- modal for the object -->

Anyone who could give me tips?

A:

You need to send back your form as html and stick it in the modal before you show it. so on click, you would first do you ajax request, and this will send back your form as html. For example,
def edit_entry(request, entry_pk):
   ....
   entry = get_object_or_404(Entry, pk=entry_pk)

   if request.method != 'POST':
       form = EntryForm(instance=entry, user=request.user)
       return HttpResponse(form.as_p())   # This will return the plain html of a form
   ....

Hope this helps!

