Skip to content

Instantly share code, notes, and snippets.

@speckone
Created June 11, 2014 22:54
Show Gist options
  • Save speckone/6591f424588753f3ddbb to your computer and use it in GitHub Desktop.
Save speckone/6591f424588753f3ddbb to your computer and use it in GitHub Desktop.
flask marshmalllow attempt 1
services = db.Table('services',
db.Column('alert_id', db.Integer, db.ForeignKey('alert.id')),
db.Column('service_id', db.Integer, db.ForeignKey('service.id')))
class Alert(CRUDMixin, db.Model):
__tablename__ = 'alert'
subject = db.Column(db.String, nullable=False)
body = db.Column(db.UnicodeText, nullable=False)
opened = db.Column(db.DateTime)
resolved = db.Column(db.DateTime)
services_affected = db.relationship('Service', secondary=services, backref=db.backref('alerts', lazy='dynamic'))
class Service(CRUDMixin, db.Model):
__tablename__ = 'service'
name = db.Column(db.String, unique=True)
def __repr__(self):
return self.name
class ServiceMarshmallow(ma.Serializer):
class Meta:
fields = ('id', 'name')
class AlertMarshmallow(ma.Serializer):
services_affected = fields.Nested(ServiceMarshmallow)
class Meta:
fields = ('id', 'subject', 'body', 'services_affected', 'opened', 'resolved')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment