XYHLF / App /routers /bonds /models.py
Mbonea's picture
initial commit
9d4bd7c
from tortoise import fields, models
from tortoise.contrib.pydantic import pydantic_model_creator
from tortoise.contrib.pydantic.creator import pydantic_queryset_creator
from tortoise.queryset import QuerySet
class Bond(models.Model):
id = fields.IntField(pk=True)
instrument_type = fields.CharField(max_length=50)
auction_number = fields.IntField()
auction_date = fields.DateField()
maturity_years = fields.CharField(max_length=10)
maturity_date = fields.DateField()
effective_date = fields.DateField()
dtm = fields.IntField()
bond_auction_number = fields.IntField()
holding_number = fields.IntField()
face_value = fields.BigIntField()
price_per_100 = fields.FloatField()
coupon_rate = fields.FloatField()
isin = fields.CharField(max_length=12, unique=True)
@staticmethod
async def get_list(data):
if type(data) == QuerySet:
parser=pydantic_queryset_creator(Bond)
return await parser.from_queryset(data)
if type(data) == type([Bond]):
return [ await i.to_dict() for i in data]
async def to_dict(self):
if type(self) == Bond:
parser=pydantic_model_creator(Bond)
return await parser.from_tortoise_orm(self)
class Meta:
table = "bonds"
unique_together = ("auction_number", "auction_date")