def handle_course(course_code, course_name, course_name_ar, course_speciality, academic_level): try: obj = Course.objects.get(course_code=course_code) print('Course found with id = ' + str(obj.course_id)) except Course.DoesNotExist: obj = Course() print('Course not found, creating new object') obj.course_name = course_name obj.course_code = course_code obj.course_name_ar = course_name_ar obj.speciality = course_speciality obj.academic_level = academic_level try: obj.save() print("Course " + course_name + ' saved in database') return obj except Exception as e: print("Error in storing the Course object") print(str(e)) return None