Re: Unable to display records in form

2023-08-23 Thread ivan harold
Maybe this could help you.

https://www.geeksforgeeks.org/django-crud-create-retrieve-update-delete-function-based-views/

On Monday, August 21, 2023 at 2:19:37 PM UTC-5 GLOBAL ENGINEERING ACADEMY 
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.
>  
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/04afb3db-c300-4267-9c29-d326eab0433fn%40googlegroups.com.


Unable to display records in form

2023-08-21 Thread GLOBAL ENGINEERING ACADEMY
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.
 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6decf54f-8187-4ff0-a8ec-2fb137120e35n%40googlegroups.com.