Commit 3327c176 authored by Willard's avatar Willard

Add dish type to forms and models

parent 25e5399e
import os.path
from canteeneo import app, db
from canteeneo.models import Stall, Dish
from canteeneo.models import Stall, Dish, DishType
from canteeneo.forms import DishRegisterForm
from canteeneo.views import flash_form_errors, stall_validate, dish_validate, FormView
......@@ -26,7 +26,9 @@ class NewDishView(FormView):
def render_get(self, stall_id):
return render_template('newdish.html', form=self.get_form(), stall=self.stall)
def get_form(self):
return DishRegisterForm()
form = DishRegisterForm()
form.dish_type.choices = [(dish_type.id, dish_type.name) for dish_type in DishType.query.all()]
return form
class DishView(View):
decorators = [login_required, dish_validate]
......
......@@ -68,6 +68,7 @@ class DishRegisterForm(FlaskForm):
description = TextAreaField('Description', [DataRequired()])
image = FileField('Image')
price = DecimalField('Price', [DataRequired()])
dish_type = SelectField('Type', coerce=int)
def validate(self, editing=False):
if not FlaskForm.validate(self):
......
......@@ -33,6 +33,7 @@ class Dish(db.Model):
description = db.Column(db.Text)
price = db.Column(db.Float)
stall_id = db.Column(db.Integer, db.ForeignKey('stall.id'))
type_id = db.Column(db.Integer, db.ForeignKey('dish_type.id'))
image_path = db.Column(db.String(160), unique=True)
favorites = db.relationship('User', secondary=dish_favorites, backref=db.backref('dish', lazy='dynamic'))
reviews = db.relationship('DishReview', backref='dish', lazy='dynamic')
......@@ -44,6 +45,14 @@ class Dish(db.Model):
self.stall_id = stall_id
self.image_path = image_path
class DishType(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(80))
dishes = db.relationship('Dish', backref='type', lazy='dynamic')
def __init__(self, name):
self.name = name
class Owner(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(80))
......@@ -80,6 +89,7 @@ class Owner(db.Model):
class Location(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(80))
stalls = db.relationship('Stall', backref='location', lazy='dynamic')
def __init__(self, name):
self.name = name
......
......@@ -19,6 +19,9 @@
<div class="input-row">
{{ form.price.label(class_="field-label") }} {{ form.price(class_="text-field", type="number", style="width: 5em;") }}
</div>
<div class="input-row">
{{ form.dish_type.label(class_="field-label") }} {{ form.dish_type(class_="text-field") }}
</div>
</div>
<div class="dashboard-row">
<button type="submit">Apply</button>
......
......@@ -19,6 +19,9 @@
<div class="input-row">
{{ form.price.label(class_="field-label") }} {{ form.price(class_="text-field", type="number", style="width: 5em;") }}
</div>
<div class="input-row">
{{ form.dish_type.label(class_="field-label") }} {{ form.dish_type(class_="text-field") }}
</div>
</div>
<div class="dashboard-row">
<button type="submit">Add</button>
......
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