Skip to content

Instantly share code, notes, and snippets.

@yaheath
Created July 15, 2018 21:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yaheath/ff2d714da1559c4787bb9524248003b1 to your computer and use it in GitHub Desktop.
Save yaheath/ff2d714da1559c4787bb9524248003b1 to your computer and use it in GitHub Desktop.
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