Commit 3ce6b7d8 authored by Willard's avatar Willard

Show more information about each dish in stalls

parent da2d39ff
......@@ -26,6 +26,14 @@ class Stall(db.Model):
self.description = description
self.owner_id = owner_id
self.location_id = location_id
def average_rating(self):
total = 0
for review in self.reviews.all():
total += review.rating
if len(self.reviews.all()) > 0:
total /= len(self.reviews.all())
return total
class Dish(db.Model):
id = db.Column(db.Integer, primary_key=True)
......@@ -45,6 +53,14 @@ class Dish(db.Model):
self.stall_id = stall_id
self.image_path = image_path
def average_rating(self):
total = 0
for review in self.reviews.all():
total += review.rating
if len(self.reviews.all()) > 0:
total /= len(self.reviews.all())
return total
class DishType(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(80))
......
......@@ -16,7 +16,7 @@
{% if dishes|length > 0 %}
<table class="table">
<tr>
<th>Image</th><th>Name</th><th>Description</th><th>Price</th><th>Controls</th>
<th>Image</th><th>Name</th><th>Description</th><th>Price</th><th>Feedback</th><th>Controls</th>
</tr>
{% for dish in dishes %}
<tr>
......@@ -25,6 +25,11 @@
<td>{{dish.description}}</td>
<td>Php {{dish.price}}</td>
<td>
{{dish.favorites|length}} people favorited this.<br>
{{dish.reviews.all()|length}} reviews, average {{dish.average_rating()}}
</td>
<td>
<a class="btn btn-default btn-block btn-lg" href="{{ url_for('view_dish', stall_id=stall.id, dish_id=dish.id) }}">View</a>
<a class="btn btn-primary btn-block btn-lg "href="{{ url_for('edit_dish', stall_id=stall.id, dish_id=dish.id) }}">Edit</a>
<form action="{{ url_for('delete_dish', stall_id=stall.id, dish_id=dish.id) }}" method="POST" onsubmit="return confirm('Are you sure you want to delete {{dish.name}}')">
<button type="submit" class="btn btn-danger btn-block btn-lg">Delete</button></a>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment