def add_users(): admin = User( username='******', role=UserRole.ADMIN, school=School.query.filter_by(name="Swaffham Prior Primary").first()) admin.password = "******" prior_admin = User( username='******', role=UserRole.SINGLE_SCHOOL_RW, school=School.query.filter_by(name="Swaffham Prior Primary").first()) prior_admin.password = "******" bulbeck_ro = User( username='******', role=UserRole.SINGLE_SCHOOL_RO, school=School.query.filter_by(name="Swaffham Bulbeck Primary").first()) bulbeck_ro.password = "******" DB.session.add(prior_admin) DB.session.add(bulbeck_ro) DB.session.add(admin) DB.session.commit()
def post(self): name = request.json['name'] age = request.json['age'] profile = request.json['profile'] organisation = request.json['organisation'] new_user = User(name, age) new_user.profile = UserProfile(new_user.id, profile['address']) for i in organisation: new_organisation = Organisation(new_user.id, i['name']) new_user.organisation.append(new_organisation) db.session.add(new_organisation) db.session.add(new_user.profile) db.session.add(new_user) db.session.commit() return user_schema.jsonify(new_user)