Author: Pedro Lucas Porcellis <pedrolucasporcellis@gmail.com>
Add price to the product form
src/blueprints/products.py | 3 ++- src/templates/new_product.html | 5 +++++ src/types/product.py | 4 +++-
diff --git a/src/blueprints/products.py b/src/blueprints/products.py index 4545a77d63eea1f26fe500658455885cf27a0b7b..08cb9cc5f377618cc94b099cb11b50748c377a98 100644 --- a/src/blueprints/products.py +++ b/src/blueprints/products.py @@ -39,7 +39,8 @@ product = Product( title = title, description = params.get('description'), group_id = group_id, - category_id = category_id + category_id = category_id, + price = params.get('price') ) product.create() diff --git a/src/templates/new_product.html b/src/templates/new_product.html index cf1b8450ea0b818dee23e98e1fc11c0223dda3ec..a5619136c3ed36d1ab0b42f906accfda1b766fe5 100644 --- a/src/templates/new_product.html +++ b/src/templates/new_product.html @@ -41,6 +41,11 @@ {% endfor %} </select> </div> + <div class="form-section"> + <label for="price">Price</label> + <input type="text" placeholder="14.20" name="price" /> + </div> + <div class="form-action"> <button type="submit" rel="button">Criar Produto</button> </div> diff --git a/src/types/product.py b/src/types/product.py index 4f8ca499c9214bd6072f7c9ae783e79938f2a667..5a9e65e591223237384643e1b369adf47a747fcf 100644 --- a/src/types/product.py +++ b/src/types/product.py @@ -17,11 +17,12 @@ balance = db.relationship("Balance", backref = "product", lazy = True, uselist = False) - def __init__(self, title, description, group_id, category_id): + def __init__(self, title, description, group_id, category_id, price): self.title = title self.description = description self.group_id = group_id self.category_id = category_id + self.price = price def create(self): db.session.add(self) @@ -38,6 +39,7 @@ "title": self.title, "description": self.description, "group_id": self.group_id, "category_id": self.category_id, + "price": self.price, "created_at": self.created_at.__str__(), "updated_at": self.updated_at.__str__(), "balance": (self.balance.to_json() if self.balance else None)