Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class NamedSchema(Schema):
- id = fields.Int()
- name = fields.Str()
- class SearchTransactionsSchema(SQLAlchemySchema):
- class Meta:
- model = Transaction
- load_instance = True
- id = auto_field()
- provider_transaction_id = auto_field()
- service_id = auto_field()
- # service = fields.Nested("ServiceSchema")
- provider_id = auto_field()
- provider_service_id = auto_field()
- protocol_id = auto_field()
- amount = auto_field(as_string=True)
- status = fields.Int()
- #
- # def get_status_name(self, values):
- # return TRANSACTION_STATUSES.get(values.Transaction.status)
- #
- # def convert_to_loc_time(self, values):
- # return values.Transaction.created_at.astimezone(tz.gettz('Europe/Kiev')).strftime('%Y-%m-%d %H:%M:%S')
- status_name = fields.Method("get_status_name")
- created_at = fields.Method("convert_to_loc_time")
- def get_status_name(self, values):
- return TRANSACTION_STATUSES.get(values.status)
- def convert_to_loc_time(self, values):
- return values.created_at.astimezone(tz.gettz('Europe/Kiev')).strftime('%Y-%m-%d %H:%M:%S')
- ############################
- transactions = db.session.query(Transaction, Service).join(Service, Transaction.service_id == Service.id)
- trxs=[]
- for t in transactions.all():
- # trxs.append(SearchTransactionsSchema().dump(t))
- trxs.append({**SearchTransactionsSchema().dump(t[0]), 'service': NamedSchema().dump(t[1])})
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement