def form(request): subjects = subjectdata() form = None if request.method == 'POST': form = subjectform(request.POST , instance = subjects) if form.is_valid(): subject = form.save(commit = False) subject.save() return redirect('scheduler:show') pass # request.method == 'GET' else: form = subjectform(instance = subjects) return render_to_response('scheduler/subjectform.html', {'form': form} , context_instance = RequestContext(request) )
def csv_form(request): if request.method != 'POST': return HttpResponseRedirect('/') file = request.FILES['csvfile'] path = os.path.join(settings.BASE_DIR , file.name) destination = open(path, 'wb') for chunk in file.chunks(): destination.write(chunk) os.rename(settings.BASE_DIR + "/" + str(file) , "classall.csv") shutil.copy(settings.BASE_DIR + "/classall.csv" , settings.BASE_DIR + "/scheduler/static/classall.csv") df = pd.read_csv('classall.csv' , header = None) for i in range(len(df.as_matrix())): insert_data = subjectdata(subject_name = df.ix[i,1] , teacher = df.ix[i,2] , room = df.ix[i,3]) insert_data.save() return render_to_response('scheduler/create.html')