Unable to display records in form

37 views
Skip to first unread message

GLOBAL ENGINEERING ACADEMY

unread,
Aug 21, 2023, 3:19:37 PM8/21/23
to Django users
Hai, 
I am trying to learn django on my own. I have created a small project of a shop. I am able to insert items but when i try to fetch items for updating / deleting, the form is not populated . only the primary key is shown.
 def updatedeleteitem(request):
    item=None
    updatedeleteform=None
    if request.method=='POST':
        keysearchform=KeysearchForm(request.POST)
        if keysearchform.is_valid():
            itemcode=keysearchform.cleaned_data['itemcode']
            try:
                item=Item.objects.get(itemcode=itemcode)
                updatedeleteform=UpdatedeleteForm(request.POST, instance=item)
                           
                if updatedeleteform.is_valid():
                    updatedeleteform.save()
                    transaction.commit()
                    return redirect('itemlist')
            except Item.DoesNotExist:
                pass
    else:
        keysearchform=KeysearchForm()
       
    return render(request,'updatedeleteitem.html',
                  {'keysearchform' : keysearchform,
                   'updatedeleteform' : updatedeleteform, 'item' : item})
___________________________________________________________________
class UpdatedeleteForm(forms.ModelForm):
    class Meta:
        model=Item
        fields=['itemcode', 'itemname', 'unitpr', 'qty']
       
class KeysearchForm(forms.Form):
    itemcode=forms.CharField(label='item code', max_length=5)
   

These are the view & Forms I am using. Please help.
 

ivan harold

unread,
Aug 23, 2023, 10:14:41 AM8/23/23
to Django users

Ryan Nowakowski

unread,
Aug 26, 2023, 9:02:02 AM8/26/23
to django...@googlegroups.com
Share your your templates as well
Reply all
Reply to author
Forward
0 new messages