fix_file_path(note)
+
# Import from json
print 'updating %i schools' % len(school_dicts)
for school in school_dicts:
s = School(**school)
s.save()
+# Only Save this scool if we actually need it.
+arbitrary_school = School(name='No School', slug='no_school')
+
print 'updating %i courses' % len(course_dicts)
for course in course_dicts:
course['updated_at'] = datetime.datetime.utcnow()
# Somc courses have no school_id using arbitrary one for these
if not course['school_id']:
print 'Using arbitrary school_id for course id:', course['id'], '-', course['name']
- course['school_id'] = School.objects.all()[0].id
+ course['school_id'] = arbitrary_school.id
+ arbitrary_school.save()
c = Course(**course)
c.save()
# Import the Notes
print 'updating %i notes' % len(note_dicts)
+
+arbitrary_course = Course(name='No Course', slug='no_course', school=arbitrary_school)
+
for note in note_dicts:
if not note['course_id']:
print 'using arbitrary course id for note_id:', note['id'], '-', note['name']
- note['course_id'] = Course.objects.all()[0].id
+ note['course_id'] = arbitrary_course.id
+ arbitrary_school.save()
+ arbitrary_course.save()
if 'slug' not in note:
path, fn = split(note['file_path'])