fix schema and primary key

* version is an additional primary key so we need to indicate that
* schema no longer relies on Template model, and uses nested user
This commit is contained in:
Leo Hemsted
2016-08-08 16:57:39 +01:00
parent 049514d4b2
commit c820938ced
5 changed files with 18 additions and 19 deletions

View File

@@ -172,17 +172,11 @@ class TemplateSchema(BaseTemplateSchema):
class TemplateHistorySchema(BaseSchema):
class Meta:
# Use the base model class that the history class is created from
model = models.Template
# We have to use a method here because the relationship field on the
# history object is not created.
created_by = fields.Method("populate_created_by", dump_only=True)
created_by = fields.Nested(UserSchema, only=['id', 'name', 'email_address'], dump_only=True)
created_at = field_for(models.Template, 'created_at', format='%Y-%m-%d %H:%M:%S.%f')
def populate_created_by(self, data):
usr = models.User.query.filter_by(id=data.created_by_id).one()
return {'id': str(usr.id), 'name': usr.name, 'email_address': usr.email_address}
class Meta:
model = models.TemplateHistory
class NotificationsStatisticsSchema(BaseSchema):