def create_course(): post_body = json.loads(request.data) code = post_body.get('code') name = post_body.get('name') course = Course(code=code, name=name, assignments=[], users=[]) db.session.add(course) db.session.commit() return json.dumps({'success': True, 'data': course.serialize()}), 201
def create_course(): post_body = json.loads(request.data) code = post_body.get('code', '') name = post_body.get('name', '') course = Course(code=code, name=name) db.session.add(course) db.session.commit() data = course.serialize() data['assignments'] = [a.serialize() for a in course.assignments] data['instructors'] = [t.serialize() for t in course.teachers] data['students'] = [s.serialize() for s in course.students] return json.dumps({'success': True, 'data': data}), 201