Developing RESTful APIs with Python and Flask

PHOTO EMBED

Thu Mar 03 2022 07:17:31 GMT+0000 (Coordinated Universal Time)

Saved by @morristech #python

from marshmallow import post_load

from .transaction import Transaction, TransactionSchema
from .transaction_type import TransactionType


class Expense(Transaction):
  def __init__(self, description, amount):
    super(Expense, self).__init__(description, -abs(amount), TransactionType.EXPENSE)

  def __repr__(self):
    return '<Expense(name={self.description!r})>'.format(self=self)


class ExpenseSchema(TransactionSchema):
  @post_load
  def make_expense(self, data):
    return Expense(**data)
content_copyCOPY

https://auth0.com/blog/developing-restful-apis-with-python-and-flask/