[Django]-Editing existing entries in Django forms

5👍

You’ve imagined an attribute called request.item. There’s no such thing. You need to get the item from the database, via the ID passed into the function as alecxe showed.

def edit(request, item_id):
    item = Item.objects.get(pk=item_id)
    if request.method == 'POST':
        form = EditItemForm(request.POST, instance=item)

1👍

edit() view should allow a keyword argument item_id:

def edit(request, item_id=None):
    if request.method == 'POST':
        ...
👤alecxe

Leave a comment