def handle_parent(): #----------------------------CREATE POST if request.method == 'POST': body = request.get_json() if body is None: return "The request body is null", 400 if 'person_id' not in body: return "You need to specify the person_id", 400 if 'father_id' not in body: return "You need to specify the father_id", 400 if 'mother_id' not in body: return "You need to specify the mother_id", 400 relation = Parent() relation.own_id = body['person_id'] relation.father_id = body['father_id'] relation.mother_id = body['mother_id'] relation.relativity ='person id: '+ str(body['person_id'])+' - '+'father id: '+str(body['father_id'])+' - '+'mother id: '+str(body['mother_id']) verification = Parent.query.filter_by(own_id = body['person_id']).first() if verification is None: db.session.add(relation) elif relation.own_id == verification.own_id: return "This user already has a RELATION", 400 else: db.session.add(relation) db.session.commit() response_body = {"msg": "You POST a RELATION"} return jsonify(response_body), 200