views:

21

answers:

0

How can i go about making list that do this in Django.

I want it to look like:

Item A    
add

Item B    
add 

Item C    
add

where items are from Item models. When the add button is clicked, the item will be added to a list model.

I use modelformset so that i could get Item list which is already populated in the Item model. I have been tinkering with modelformset where i tried to get it print the id fields to see whether it works.

def all_item(request):
   ItemForm = modelformset_factory(Item, fields=('id'))
   if request.method == 'POST':
        formset = ItemForm(request.POST)
        if formset.is_valid():
           print formset.cleaned_data['id']
   else:
      formset = ItemForm(queryset=Item.objects.order_by('id'))
   return render_to_response('index.html',locals(),context_instance=RequestContext(request))

Not working. How do i make only the click 'id' get POSTED instead of all the items?

How do i go about doing this. Is modelformset the way to go? Is there better way to do this?

Im doing this as a project to learn django nuts & bolts.