def editplatform(request,pid): response={} plat=Platform.objects.get(id=pid) if request.method == 'POST': form=PlaformForm(request.POST,instance=plat) if form.is_valid(): post=form.save(commit=False) post.addedby=request.user post.lat=request.POST['latitude'] post.longt=request.POST['longitude'] post.save() form.save_m2m() plat=Platform.objects.get(id=post.id) for org in plat.organisations.all(): try: OrgMap.objects.get(org=org,platform=plat) except: omap=OrgMap() omap.org=org omap.platform=plat omap.save() return HttpResponseRedirect('/viewcollegeplatforms') else: print form.errors response['message']='Please check the form again' else: form=PlaformForm(instance=plat) response['form']=form response['platform']=plat return render(request,'site/editplatform.html',response)
def addplatform(request): response={} if request.method == 'POST': form=PlaformForm(request.POST) if form.is_valid(): post=form.save(commit=False) post.addedby=request.user post.lat=request.POST['latitude'] post.longt=request.POST['longitude'] post.save() form.save_m2m() if request.FILES['banner']: post.banner=request.FILES['banner'] else: post.banner='default.jpg' post.save() plat=Platform.objects.get(id=post.id) for org in plat.organisations.all(): omap=OrgMap() omap.org=org omap.platform=plat omap.save() return HttpResponseRedirect('/viewcollegeplatforms') else: print form.errors response['message']='Please check the form again' else: form=PlaformForm() response['form']=form return render(request,'site/addplatform.html',response)