First data
This commit is contained in:
parent
7ca0e36946
commit
a6f71195fd
3 changed files with 40 additions and 4 deletions
20
app/fatmodels.py
Normal file
20
app/fatmodels.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
from models import User, Location, Order, OrderItem
|
||||
|
||||
|
||||
class CountableModel:
|
||||
|
||||
@classmethod
|
||||
def amount(cls):
|
||||
return cls.query.count()
|
||||
|
||||
|
||||
class FatLocation(Location, CountableModel): pass
|
||||
|
||||
|
||||
class FatOrder(Order, CountableModel): pass
|
||||
|
||||
|
||||
class FatUser(User, CountableModel): pass
|
||||
|
||||
|
||||
class FatOrderItem(OrderItem, CountableModel): pass
|
|
@ -1,6 +1,14 @@
|
|||
{% extends "layout.html" -%}
|
||||
{% set active_page = "stats" -%}
|
||||
{% block container %}
|
||||
<h1>Stats bruh</h1>
|
||||
<p>TOP 4</p>
|
||||
<h2>Stats bruh</h2>
|
||||
<div class="jumbotron">
|
||||
<h5>
|
||||
In
|
||||
<strong>{{ data.order_amount }}</strong> orders,
|
||||
<strong>{{ data.user_amount }}</strong> users have ordered
|
||||
<strong>{{ data.orderitem_amount }}</strong> items in
|
||||
<strong>{{ data.location_amount }}</strong> locations.
|
||||
</h5>
|
||||
</div>
|
||||
{% endblock %}
|
|
@ -1,7 +1,15 @@
|
|||
from app import app
|
||||
from flask import render_template
|
||||
|
||||
from fatmodels import FatLocation, FatOrder, FatOrderItem, FatUser
|
||||
from app import app
|
||||
|
||||
|
||||
@app.route('/stats/')
|
||||
def stats():
|
||||
return render_template('stats.html')
|
||||
data = {
|
||||
'order_amount': FatOrder.amount(),
|
||||
'location_amount': FatLocation.amount(),
|
||||
'user_amount': FatUser.amount(),
|
||||
'orderitem_amount': FatOrderItem.amount()
|
||||
}
|
||||
return render_template('stats.html', data=data)
|
||||
|
|
Loading…
Reference in a new issue