relationship zwischen user und creditlist

fixed bug: json mit ['userID'] wird nicht mehr überschrieben
This commit is contained in:
Tim Gröger 2019-04-23 20:26:20 +02:00
parent 2ba7240611
commit 7bec023d57
4 changed files with 6 additions and 2 deletions

View File

@ -55,3 +55,5 @@ class CreditList(db.Model):
last_schulden = db.Column(db.Integer, nullable=False, default=0)
year = db.Column(db.Integer, nullable=False, default=datetime.now().year)
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)

View File

@ -23,6 +23,8 @@ class User(db.Model):
group = db.Column(db.String, nullable=False)
password = db.Column(db.String, nullable=False)
geruechte = db.relationship('CreditList', backref='user', lazy=True)
def toJSON(self):
""" Create Dic to dump in JSON

View File

@ -48,7 +48,7 @@ def _getFinanzer():
users = User.query.all()
dic = {}
for user in users:
dic["userID"] = user.toJSON()
dic[user.userID] = user.toJSON()
return jsonify(dic)
return jsonify({"error": "permission denied"}), 401
@ -92,6 +92,6 @@ def getFinanzer():
users = User.query.all()
dic = {}
for user in users:
dic["userID"] = user.toJSON()
dic[user.userID] = user.toJSON()
print(dic)
return jsonify(dic)

Binary file not shown.