ciclos

ref: master

core/types/group.py


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from sqlalchemy import Integer, Column, DateTime, String
from sqlalchemy.orm import relationship
from core.database import Base
from datetime import datetime as dt
from core.types.product import Product

class Group(Base):
    __tablename__ = 'groups'

    id = Column(Integer, primary_key=True)
    name = Column(String(255), nullable=False)
    location = Column(String(255), nullable=False)
    lat = Column(String(255))
    lng = Column(String(255))
    created_at = Column(DateTime, nullable=False)
    updated_at = Column(DateTime, nullable=False)

    products = relationship("Product", backref="group", lazy=True)

    def __init__(self, name, location, lat, lng):
        self.name = name
        self.location = location
        self.lat = lat
        self.lng = lng

    def to_json(self):
        return {
            "id": self.id,
            "name": self.name,
            "location": self.location,
        }