How can I fill up form with model object data?

前端 未结 2 863
陌清茗
陌清茗 2021-01-31 15:15

I want to fill up form with data from model instance. But my form has less fields than model. If I have code like this:

class Item(models.Model)
    name = model         


        
2条回答
  •  无人及你
    2021-01-31 15:48

    def bound_form(request, id): 
        item = Item.objects.get(id=id) 
        form = ItemForm(initial={'name': item.name}) 
        return render_to_response('bounded_form.html', {'form': form}) 
    

提交回复
热议问题