def PostCreate(request, pk=None): instance = get_object_or_404(event, pk=pk) form = eventform(request.POST or None, instance=instance) if form.is_valid(): link = "/eventpage/" link = link + form.cleaned_data.get('event_id') + "/" if form.cleaned_data.get('winner1') != "nil" or form.cleaned_data.get( 'winner2') != "nil" and form.cleaned_data.get( 'winner3') != "nil" or form.cleaned_data.get( 'short_list') != "nil": event_name = form.cleaned_data.get('event_name') eventid = form.cleaned_data.get('event_id') winners.objects.filter(event=event_name).delete() eventlist = event.objects.filter(event_id=eventid) winner1 = form.cleaned_data.get('winner1') winner2 = form.cleaned_data.get('winner2') winner3 = form.cleaned_data.get('winner3') participants = form.cleaned_data.get('participants') participants.split(',') winner_list = [ winner1.split(','), winner2.split(','), winner3.split(',') ] if len(winner_list) != 0: for lists in winner_list: for Exid in lists: if eventlist[0].paid == False: queryset = userinfo.objects.filter(excelid=Exid) for obj in queryset: name = obj.name college = obj.college if not winners.objects.filter(event=event_name, excelid=Exid): obj1_winner = winners( event=event_name, name=name, college=college, position=winner_list.index(lists) + 1, excelid=Exid) obj1_winner.save() else: queryset = paid_userinfo.objects.filter( excelid=Exid) for obj in queryset: name = obj.name college = obj.college if not paid_winners.objects.filter( event=event_name, excelid=Exid): obj1_winner = paid_winners( event=event_name, name=name, college=college, position=winner_list.index(lists) + 1, excelid=Exid) obj1_winner.save() if form.cleaned_data.get( 'participants') != "nil" and form.cleaned_data.get( 'participants') != "": event_name = form.cleaned_data.get('event_name') event_id = form.cleaned_data.get('event_id') eventlist = event.objects.filter(event_id=event_id) participants = form.cleaned_data.get('participants').split(",") if len(participants) != 0: stri = event_id for Exid in participants: if Exid != "nil" and Exid != "": if eventlist[0].paid == False: queryset = userinfo.objects.get(excelid=Exid) if queryset.participated_events == "nil": queryset.participated_events = "" pp = queryset.participated_events.split(",") if stri not in pp: queryset.participated_events = queryset.participated_events + stri + "," queryset.save() instance = form.save(commit=False) instance.save() return HttpResponseRedirect(link) context = { "form": form, } return render(request, "test.html", context)
def postcreate(request, pk=None): instance = get_object_or_404(event, pk=pk) form = eventform(request.POST or None, instance=instance) if form.is_valid(): link="/eventpage/" link=link+form.cleaned_data.get('event_id')+"/" if form.cleaned_data.get('winner1')!="nil" or form.cleaned_data.get('winner2')!="nil" and form.cleaned_data.get('winner3')!="nil" or form.cleaned_data.get('short_list')!="nil": event_name=form.cleaned_data.get('event_name') eventid=form.cleaned_data.get('event_id') winners.objects.filter(event=event_name).delete() eventlist=event.objects.filter(event_id=eventid) winner1=form.cleaned_data.get('winner1') winner2=form.cleaned_data.get('winner2') winner3=form.cleaned_data.get('winner3') participants=form.cleaned_data.get('participants') participants_list=participants.split(',') winner_list=[winner1.split(','),winner2.split(','),winner3.split(',') ] if len(winner_list)!=0: for lists in winner_list: for Exid in lists: if eventlist[0].paid == False : queryset=userinfo.objects.filter(excelid=Exid) for obj in queryset: name=obj.name college= obj.college if not winners.objects.filter(event=event_name,excelid=Exid): obj1_winner=winners(event=event_name,name=name,college=college,position=winner_list.index(lists)+1,excelid=Exid) obj1_winner.save() else : queryset=paid_userinfo.objects.filter(excelid=Exid) for obj in queryset: name=obj.name college= obj.college if not paid_winners.objects.filter(event=event_name,excelid=Exid): obj1_winner=paid_winners(event=event_name,name=name,college=college,position=winner_list.index(lists)+1,excelid=Exid) obj1_winner.save() if form.cleaned_data.get('participants')!="nil" and form.cleaned_data.get('participants')!="": event_name=form.cleaned_data.get('event_name') event_id=form.cleaned_data.get('event_id') eventlist=event.objects.filter(event_id=event_id) participants=form.cleaned_data.get('participants').split(",") if len(participants)!=0: stri=event_id for Exid in participants: if Exid !="nil" and Exid !="": if eventlist[0].paid == False : queryset=userinfo.objects.get(excelid=Exid) if queryset.participated_events=="nil": queryset.participated_events="" pp=queryset.participated_events.split(",") if stri not in pp: queryset.participated_events=queryset.participated_events+stri +"," queryset.save() instance = form.save(commit=False) instance.save() return HttpResponseRedirect(link) context = { "form": form, } return render(request, "test.html", context)