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) last_schulden = db.Column(db.Integer, nullable=False, default=0)
year = db.Column(db.Integer, nullable=False, default=datetime.now().year) 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) group = db.Column(db.String, nullable=False)
password = db.Column(db.String, nullable=False) password = db.Column(db.String, nullable=False)
geruechte = db.relationship('CreditList', backref='user', lazy=True)
def toJSON(self): def toJSON(self):
""" Create Dic to dump in JSON """ Create Dic to dump in JSON

View File

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

Binary file not shown.