32 lines
1.0 KiB
Python
32 lines
1.0 KiB
Python
# coding=UTF-8
|
|
|
|
from api.extensions import db
|
|
from .product import Currencies
|
|
from sqlalchemy.orm import validates
|
|
from sqlalchemy.ext.associationproxy import association_proxy
|
|
|
|
|
|
class Market(db.Model):
|
|
__tablename__ = "markets"
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
name = db.Column(db.String(255))
|
|
vat = db.Column(db.Float, nullable=False)
|
|
price_adjustments = db.Column("price_adjustment", db.Float, nullable=False)
|
|
currency = db.Column(db.String(3), db.ForeignKey("product-currencies.iso3char"))
|
|
exchange_rate = db.Column(db.Float)
|
|
_pc = db.relationship(Currencies, uselist=False)
|
|
exchange_rate = association_proxy(
|
|
"_pc", "exchange_rate", creator=lambda kw: Currencies(exchange_rate=kw)
|
|
)
|
|
|
|
def to_json(self):
|
|
return {
|
|
"id": self.id,
|
|
"name": self.name,
|
|
"price_adjustment": str(self.price_adjustments),
|
|
"vat": str(self.vat),
|
|
"currency": self.currency,
|
|
"exchange_rate": str(self.exchange_rate),
|
|
}
|