Commit bd3a8a20 authored by Willard's avatar Willard

Fix dish edits not registering correctly

parent d16d55bb
...@@ -62,6 +62,7 @@ class EditDishView(FormView): ...@@ -62,6 +62,7 @@ class EditDishView(FormView):
def get_form(self): def get_form(self):
form = DishRegisterForm() form = DishRegisterForm()
form.dish_type.choices = [(dish_type.id, dish_type.name) for dish_type in DishType.query.all()] form.dish_type.choices = [(dish_type.id, dish_type.name) for dish_type in DishType.query.all()]
form.editing = True
return form return form
class DeleteDishView(View): class DeleteDishView(View):
......
...@@ -69,13 +69,14 @@ class DishRegisterForm(FlaskForm): ...@@ -69,13 +69,14 @@ class DishRegisterForm(FlaskForm):
image = FileField('Image') image = FileField('Image')
price = DecimalField('Price', [DataRequired()], render_kw={"placeholder": "Price"}) price = DecimalField('Price', [DataRequired()], render_kw={"placeholder": "Price"})
dish_type = SelectField('Type', coerce=int) dish_type = SelectField('Type', coerce=int)
editing = False
def validate(self, editing=False): def validate(self, editing=False):
if not FlaskForm.validate(self): if not FlaskForm.validate(self):
return False return False
dish = Dish.query.filter_by(name=self.name.data).first() dish = Dish.query.filter_by(name=self.name.data).first()
if not editing: if not self.editing:
if dish is not None: if dish is not None:
flash('Dish name is taken!') flash('Dish name is taken!')
return False return False
......
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