def handle(self, *args, **options): data = pickle.load(open(str(args[0]))) Section.objects.all().delete() Book.objects.all().delete() i = 0 for quarter in data: for dept in quarter['departments']: for courses in dept['courses']: newCourseName = courses['name'] for section in courses['sections']: newSectionName = section['name'] newSectionID = section['id'] for book in section['books']: newISBN = book['ISBN'] newAuthor = book['author'] newBinding = book['binding'] newPrice = book['broncoListPrice'] newEdition = book['edition'] newRequired = book['isRequired'] newtitle = book['title'] newBook = Book( isbn = newISBN, sectionID = newSectionID, required = newRequired, broncoPrice = newPrice, author = newAuthor, edition = newEdition, binding = newBinding, title = newtitle ) newBook.save() print i i +=1 for quarter in data: for dept in quarter['departments']: for courses in dept['courses']: newCourseName = courses['name'] for section in courses['sections']: newSectionID = section['id'] newSectionName = section['name'] newInstructor = section['instructor'] newQuartername = quarter['name'] newCourse = Section( quarterName = newQuartername, courseName = newCourseName, sectionID = newSectionID, sectionName = newSectionName, instructor = newInstructor) newCourse.save() print newCourse
def post(self): """ Add Section """ data = request.json c = Campus.objects.get_or_404(id=data['campus']) if Section.objects(name=data['name'], campus=c).count() > 0: abort(400, error='Name already exist') s = Section(campus=c, year=data['year'], name=data['name']) s.save() return s