Created
June 11, 2014 22:54
-
-
Save speckone/6591f424588753f3ddbb to your computer and use it in GitHub Desktop.
flask marshmalllow attempt 1
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
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