total sale

from django.shortcuts import render
from .models import Sale

def sales_report(request):
    sales = Sale.objects.all()
    total_sales = sales.aggregate(total=models.Sum('total_price'))['total']
    return render(request, 'sales_report.html', {'sales': sales, 
'total_sales': total_sales})


cal total sale:on view
from flask import Flask, render_template
from models import db, Sale

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///sales.db'
db.init_app(app)

@app.route('/sales_report')
def sales_report():
    sales = Sale.query.all()
    total_sales = sum(sale.total_price for sale in sales)
    return render_template('sales_report.html', sales=sales, 
total_sales=total_sales)

if __name__ == '__main__':
    app.run(debug=True)
  
On Thursday 6 June 2024 at 02:37:27 UTC+5:30 Ryan Nowakowski wrote:

> Take a look at 
> https://docs.djangoproject.com/en/5.0/ref/templates/builtins/#include
> On 6/4/24 7:13 AM, 'Mee “MeeGrp” Grp' via Django users wrote:
>
> I am working on an Inventory System ( just a trial - for learning 
> purposes) 
>
> platform - Python
> framework - Django
>
> VS Code/Sqlite3 
>
> Question:
>
> I have two html files 1. view_sales.html 2.total_sales.html
>
> view_sales.html
>
> <!DOCTYPE html>
> <html>
> <head>
>     <title>Sales</title>
>     <title>Product Total_price</title>
> </head>
> <body>
>     <h1>Sales</h1>
>     <table border="1">
>         <tr>
>             <th>Product</th>
>             <th>Date</th> 
>             <th>Amount</th>                     
>             <th>Quantity Sold</th>           
>             <th>Total Price</th>
>         </tr>
>         {% for sale in sales %}
>         <tr>
>             <td>{{ sale.product.product_name }}</td>
>             <td>{{ sale.date }}</td>                      
>             <td>{{ sale.amount }}</td>
>             <td>{{ sale.quantity_sold}}</td>
>             <td>{{ sale.total_price }}</td>
>         </tr>
>         
>             
>         {% endfor %}
>     </table>
>     <h2>Total Sales: {{ total_sales }}</h2>    
>
> -- 
> 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/56a9ff0a-62f2-4ec0-b8cd-5601174a862en%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/django-users/56a9ff0a-62f2-4ec0-b8cd-5601174a862en%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
>

-- 
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/4d980c1a-a102-48eb-8957-e2ce3c8cdf84n%40googlegroups.com.

Reply via email to