ciclos

commit 49d0584a5b10557c6a86831380ed63879a708b0a

Author: Pedro Lucas Porcellis <pedrolucasporcellis@gmail.com>

Add groups and Products relationships

 src/__init__.py | 2 ++
 src/blueprints/products.py | 10 ++++++++++
 src/types/group.py | 27 +++++++++++++++++++++++++++
 src/types/product.py | 13 +++++++++++++


diff --git a/src/__init__.py b/src/__init__.py
index 193b864c547019c53596ea67487d5cd2a5dd1024..4e4472f3cefbb45a12531771fddfb20dfc7622f9 100644
--- a/src/__init__.py
+++ b/src/__init__.py
@@ -24,8 +24,10 @@
     # Blueprints
     from .blueprints.basic import basic
     from .blueprints.auth import auth
+    from .blueprints.products import pro as products
     app.register_blueprint(basic)
     app.register_blueprint(auth)
+    app.register_blueprint(products)
 
     with app.app_context():
         db.create_all()




diff --git a/src/blueprints/products.py b/src/blueprints/products.py
new file mode 100644
index 0000000000000000000000000000000000000000..c66415ccb0f8a28974181021fe5b68fcabcfcdb6
--- /dev/null
+++ b/src/blueprints/products.py
@@ -0,0 +1,10 @@
+from flask import Blueprint, request, render_template, redirect, url_for
+
+pro = Blueprint('products', __name__, url_prefix = 'products')
+
+@pro.route('/', methods = ['GET', 'POST'])
+def index():
+    if request.method == 'GET':
+        return 'List of prod'
+    else:
+        return 'Create new prod'




diff --git a/src/types/group.py b/src/types/group.py
new file mode 100644
index 0000000000000000000000000000000000000000..d7c21de8b875a604ce84e23a617f6d9cc958c21c
--- /dev/null
+++ b/src/types/group.py
@@ -0,0 +1,27 @@
+from . import db
+from datetime import datetime as dt
+
+class Group(db.Model):
+    __tablename__ = 'groups'
+    
+    id = db.Column(db.Integer, primary_key = True)
+    name = db.Column(db.String(255), nullable = False)
+    location = db.Column(db.String(255), nullable = False)
+    lat = db.Column(db.String(255))
+    lng = db.Column(db.String(255))
+
+    products = db.relationship("Product", backref = "group", lazy = True)
+
+    created_at = db.Column(db.DateTime, default = dt.utcnow)
+    updated_at = db.Column(db.DateTime, default = dt.utcnow)
+
+    def __init__(self, name, location, lat, lng):
+        self.name = name
+        self.location = location
+        self.lat = lat
+        self.lng = lng
+
+    def create(self):
+        db.session.add(self)
+        db.session.commit()
+




diff --git a/src/types/product.py b/src/types/product.py
new file mode 100644
index 0000000000000000000000000000000000000000..c47301333c2d3756ee1bb29a2cc256b78dd38bf8
--- /dev/null
+++ b/src/types/product.py
@@ -0,0 +1,13 @@
+from . import db
+from datetime import datetime as dt
+
+class Product(db.Model):
+    __tablename__ = 'products'
+    id = db.Column(db.Integer, primary_key = True)
+    title = db.Column(db.String(256), nullable = False)
+    description = db.Column(db.Text)
+    group_id = db.Column(db.Integer, db.ForeignKey('groups.id'), nullable = False)
+    group = db.relationship("Group", back_populates = "products")
+
+    created_at = db.Column(db.DateTime, default = dt.utcnow)
+    updated_at = db.Column(db.DateTime, default = dt.utcnow)