Created
July 15, 2018 21:33
-
-
Save yaheath/ff2d714da1559c4787bb9524248003b1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime | |
from marshmallow_sqlalchemy import ModelSchema | |
from sqlalchemy.ext.declarative import declarative_base | |
from sqlalchemy.schema import ( | |
Column, | |
) | |
from sqlalchemy.types import ( | |
BigInteger, | |
DateTime, | |
String | |
) | |
Base = declarative_base() | |
class Customer(Base): | |
__tablename__ = 'customer' | |
id = Column(BigInteger, primary_key=True) | |
created_time = Column(DateTime, nullable=False, default=datetime.utcnow) | |
updated_time = Column(DateTime, nullable=False, default=datetime.utcnow, | |
onupdate=datetime.utcnow) | |
name = Column(String, nullable=False) | |
class CustomerSchema1(ModelSchema): | |
class Meta(ModelSchema.Meta): | |
model = Customer | |
class CustomerSchema2(ModelSchema): | |
class Meta(ModelSchema.Meta): | |
model = Customer | |
exclude = ('created_time',) | |
cs1 = CustomerSchema1() | |
print('CustomerSchema1 instantiated') | |
cs2 = CustomerSchema2() | |
print('CustomerSchema2 instantiated') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment