Saturday, June 19, 2021

Help me Please - Django and python program

html.html

<body>
<center>
<h1> </h1>
</center>
<table border=1>
<tr>
<th>ID</th>
<th>Itemname</th>
<th>Quantity</th>
<th>amount</th>
<th>Yourquantity</th>
<th>Youramount</th>
</tr>

{% for displayemp in editupdaterecord%}
<tr>
<td>{{displayemp.id}}</td>
<td>{{displayemp.Itemname}}</td>
<td>{{displayemp.quantity}} </td>
<td>{{displayemp.amount}} </td>
<td>{{displayemp.yourquantity}} </td>
<td>{{displayemp.youramount}} </td>
</tr>
{% endfor %}
</table><br><br><br>
<table border=1>
<tr>
<th>ID</th>
<th>Itemname</th>
<th>Quantity</th>
<th>amount</th>
<th>Yourquantity</th>
<th>Youramount</th>
</tr>

{% for displayemp in editupdaterecord%}
<tr>
<td>{{displayemp.id}}</td>
<td>{{displayemp.Itemname}}</td>
<td>{{displayemp.quantity}} </td>
<td>{{displayemp.amount}} </td>

<form method="POST" >

{% csrf_token %}
<td><input type="text" name="yourquantity" value="{{editupdaterecord.yourquantity}}" ></td>
<td>{{displayemp.youramount}} </td>
</tr>
{% endfor %}


</table>
<br><br><br>

<button class="button .button2">Add</button>


</form>
</body>
</html>


view.py

from django.shortcuts import render
from EditRecord.models import editupdaterecord,editupdaterecord2
from EditRecord.forms import empforms
from django.contrib import messages

def displaydata(request):
results = editupdaterecord.objects.all()
if request.method=='POST':

if request.POST.get('yourquantity'):
saverecord = editupdaterecord2()
saverecord.yourquantity=request.POST.get('yourquantity')
saverecord.save()


return render(request , 'index.html' ,{"editupdaterecord":results})


model.py

from django.db import models



class editupdaterecord(models.Model):
id = models.IntegerField(primary_key=1)
Itemname = models.CharField(max_length=100)
quantity = models.IntegerField(null=True)
amount = models.IntegerField(null=True)
yourquantity = models.IntegerField(null=True)
youramount = models.IntegerField(null=True)
class Meta:
db_table ='bill3'


forms.py
from django import forms
from django.forms import fields
from EditRecord.models import editupdaterecord

class empforms(forms.ModelForm):
class Meta:
model=editupdaterecord
fields="__all__"

I have a few errors in my program.
1. HTML
In my front view only my last text box is working and all the upper text boxes are unassessable. 
2. Database
I am getting only the user quantity in the database but not getting the itemname, price and total amount in it.

I don't know where it is going wrong, I've been stuck here for the last 4 days. I'm a beginner in django and python. Which logic is used for this program?
Please, please help me.

PFA

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAOS5mPw%2BsQf9GqTQvsAihQJTHC69P-pMPmzi%3D9_ukyPVoVfCRw%40mail.gmail.com.

No comments:

Post a Comment