Help me Please - Django and python program

73 views
Skip to first unread message

mayank sandikar

unread,
Jun 19, 2021, 9:00:24 PM6/19/21
to django...@googlegroups.com
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
django program file.txt
IMG_20210619_191152.jpg

Luciano Martins

unread,
Jun 20, 2021, 6:38:39 AM6/20/21
to Django users
Post your code on github and provide the link here

mayank sandikar

unread,
Jun 21, 2021, 2:07:25 AM6/21/21
to django...@googlegroups.com

--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/9feed719-8ab5-4523-80a1-ad062fe1999en%40googlegroups.com.

Onyemordi Daniel

unread,
Jun 21, 2021, 12:39:42 PM6/21/21
to django...@googlegroups.com
Hello, have your problem been solved if no kindly contact me on WhatsApp 08167997730 to assist you better.

mayank sandikar

unread,
Jun 22, 2021, 12:51:36 AM6/22/21
to django...@googlegroups.com
hello , sir your mobile no. is not on whatsapp. please assist me  with  this

DJANGO DEVELOPER

unread,
Jun 22, 2021, 5:29:22 AM6/22/21
to django...@googlegroups.com
according to your code, you're trying to update the product record. right?
If so, then you're doing things the right way.

mayank sandikar

unread,
Jun 22, 2021, 6:20:14 AM6/22/21
to django...@googlegroups.com
Hello sir,
I'm trying to insert the data in the table. For example in database 
Itemname quantity price user-quantity amount
pen            20          5           0                0
book          20         10          0                0

in my database I'm getting this result 
pen            20          5           0                0
book          20         10          0                0
                                             2                0

I want to take the itemname, quantity, and price in the last row as well.
In my html front view (screenshot 50) only the last text box is active in the user quantity column.

please help me.
thank you



Screenshot (49).png
Screenshot (50).png

mayank sandikar

unread,
Jun 22, 2021, 6:26:47 AM6/22/21
to django...@googlegroups.com
my index.html is

<html>
<head>
<title> Edit </title>
<style>
.button {
  border: none;
  color: black;
  padding: 15px 32px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
  margin: 4px 2px;
  cursor: pointer;
 
}

.button2 {background-color: #008CBA;}

</style>
      

</head>
<body>

      
        <center>
        <h1> </h1>
        </center>
        <table border=1>
          <tr>
            <th>ID</th>
            <th>Itemname</th>
            <th>Quantity</th>
           
             <th>rate</th>
              <th>amount</th>
          </tr>
          
          {% for displayemp in editupdaterecord%}
          <tr>
          <td>{{displayemp.id}}</td>
          <td>{{displayemp.Itemname}}</td>
          <td>{{displayemp.quantity}} </td>
           <td>{{displayemp.rate}} </td>
          <td>{{displayemp.basicamount}} </td>
          
          </tr> 
           {% endfor %} 
           </table><br><br><br>

          <form method="POST" action="/">
         {% csrf_token %} 

        <table border=1>
          <tr>
            <th>ID</th>
            <th>Itemname</th>
            <th>Quantity</th>
       
            <th>userquantity</th>
            <th>amount</th>
          </tr>
          
          {% for displayemp in editupdaterecord%}
          <tr>
          <td>{{displayemp.id}}</td>
          <td>{{displayemp.Itemname}}</td>
          <td>{{displayemp.quantity}} </td>
        

          <form  method="POST" >
     
           {% csrf_token %}
                      <td><input type="text" name="userquantity" value="{{editupdaterecord.userquantity}}"   ></td>
           <td>{{displayemp.amount2}} </td>
          </tr> 
           {% endfor %} 
                    

           </table>
<br><br><br>
          
            <button class="button .button2">Add</button>
      
           
</form>
</body>
</html>



mayank sandikar

unread,
Jun 22, 2021, 6:28:09 AM6/22/21
to django...@googlegroups.com
view.py 
def displaydata(request):
   results = editupdaterecord.objects.all()


   if request.method=='POST':
     if request.POST.get('userquantity')  :
         quantity = request.POST.get('userquantity')
         a = editupdaterecord.objects.all()
         print(a)
       #  if results in a < quantity:    
         saverecord = editupdaterecord(userquantity = quantity)
         saverecord.save()
         
   return render(request , 'index.html' ,{"editupdaterecord":results})

mayank sandikar

unread,
Jun 22, 2021, 6:28:52 AM6/22/21
to django...@googlegroups.com
models.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(blank=Truenull=Truedefault=0)
    basicamount = models.IntegerField(blank=Truenull=Truedefault=0)
    rate = models.IntegerField(blank=Truenull=Truedefault=20)
    userquantity = models.IntegerField(blank=Truenull=Truedefault=0)
    amount2 = models.IntegerField(blank=Truenull=Truedefault=0)
    class Meta:
        db_table ='bill3'

mayank sandikar

unread,
Jun 22, 2021, 6:29:26 AM6/22/21
to django...@googlegroups.com
forms.py

from django import forms
from django.forms import fields
from project.models import editupdaterecord

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

DJANGO DEVELOPER

unread,
Jun 22, 2021, 6:33:22 AM6/22/21
to django...@googlegroups.com
First of all please remove the for loop from your form.
secondly please add<td>{{displayemp.userquantity_field}}</td>
          <td>{{displayemp.amount_field}} </td>

DJANGO DEVELOPER

unread,
Jun 22, 2021, 6:37:55 AM6/22/21
to django...@googlegroups.com
          <tr>
          <td>{{editupdaterecord.id}}</td>
          <td>{{editupdaterecord.Itemname}}</td>
          <td>{{editupdaterecord.quantity}} </td>
<td>{{editupdaterecord.yourquantity}} </td>
         <td>{{editupdaterecord.youramount}} </td>

          <form  method="POST" >
     
           {% csrf_token %}
                      <td><input type="text" name="userquantity" value="{{editupdaterecord.userquantity}}"   ></td>
           <td>{{displayemp.amount2}} </td>
          </tr> 
           {% endfor %} 
                    

           </table>
<br><br><br>
          
            <button class="button .button2">Add</button>
      
           
</form>
</body>
</html>

DJANGO DEVELOPER

unread,
Jun 22, 2021, 6:45:53 AM6/22/21
to django...@googlegroups.com
is your code working now?

mayank sandikar

unread,
Jun 22, 2021, 7:00:33 AM6/22/21
to django...@googlegroups.com
Thank you sir, the html problem is solved, but I don't know how to insert itemname, quantity and rate in the database

Screenshot (55).png

DJANGO DEVELOPER

unread,
Jun 22, 2021, 7:11:19 AM6/22/21
to django...@googlegroups.com
def insetdata(request):
    product_form = your_product_form()
    if request.method == 'POST':
        product_form = your_product_form(request.POST, request.FILES)
        if product_form.is_valid:
            product_form.save()
            return redirect('put your product's url name value here')
    return render(request, 'your template path here', {'product':product_form})

DJANGO DEVELOPER

unread,
Jun 22, 2021, 7:11:43 AM6/22/21
to django...@googlegroups.com
follow this code's pattern but remember one thing that you have to follow it according to your needs.

DJANGO DEVELOPER

unread,
Jun 22, 2021, 7:12:24 AM6/22/21
to django...@googlegroups.com
request.FILES used when we need to insert images as well. if there is no image field then remove the request.FILES.

mayank sandikar

unread,
Jun 22, 2021, 12:45:17 PM6/22/21
to django...@googlegroups.com
Thank you sir, sorry for all the troubles.

DJANGO DEVELOPER

unread,
Jun 22, 2021, 10:40:12 PM6/22/21
to django...@googlegroups.com
is it resolved now? or still want some help?

DJANGO DEVELOPER

unread,
Jun 22, 2021, 10:40:39 PM6/22/21
to django...@googlegroups.com
+923012876771, you can send me your queries here.

mayank sandikar

unread,
Jun 22, 2021, 11:45:39 PM6/22/21
to django...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages