Share your your templates as well
On August 21, 2023 12:23:35 AM CDT, GLOBAL ENGINEERING ACADEMY <geakylm@gmail.com> wrote:
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.
No comments:
Post a Comment