From 76da4388ebce38db8cb90dd6af490d1568a1c095 Mon Sep 17 00:00:00 2001 From: lza_menace Date: Sun, 9 Jan 2022 21:03:16 -0800 Subject: [PATCH] show user data in meme api export --- suchwowx/models.py | 4 ++++ suchwowx/routes/api.py | 1 + 2 files changed, 5 insertions(+) diff --git a/suchwowx/models.py b/suchwowx/models.py index 44fa732..ebcb78b 100644 --- a/suchwowx/models.py +++ b/suchwowx/models.py @@ -43,6 +43,10 @@ class User(db.Model): moderator = db.relationship('Moderator', back_populates='user') memes = db.relationship('Meme', back_populates='user') + def as_dict(self): + return {c.key: getattr(self, c.key) + for c in inspect(self).mapper.column_attrs if c.key != 'nonce'} + def __repr__(self): return str(self.handle) diff --git a/suchwowx/routes/api.py b/suchwowx/routes/api.py index 93099fb..d39cbfe 100644 --- a/suchwowx/routes/api.py +++ b/suchwowx/routes/api.py @@ -20,6 +20,7 @@ def memes(): memes = Meme.query.filter(Meme.approved == True).all() for meme in memes: all_memes[meme.id] = meme.as_dict() + all_memes[meme.id]['user'] = meme.user.as_dict() return jsonify(all_memes)