def profile_update(request, user_id): user = User.objects.get(id=user_id) if request.method == "POST": form = UserForm(request.POST, request.FILES, instance=user) if form.is_valid(): form.save() return redirect("profile") else: form = UserForm(instance=user) data = {"user": request.user, "form": form} return render(request, "profile/profile_update.html", data)
def profile(request): scores = Score.objects.filter(user__username=request.user) match_leader = Score.objects.filter(game="memory", user__username=request.user).order_by('score')[:10] match_avg = Score.objects.filter(game="memory", user__username=request.user).aggregate(Avg('score')) snake_leader = Score.objects.filter(game="snake", user__username=request.user).order_by('-score')[:10] snake_avg = Score.objects.filter(game="snake", user__username=request.user).aggregate(Avg('score')) print match_leader print scores if request.method == "POST": form = UserForm(request.POST, request.FILES, instance=request.user) if form.is_valid(): form.save() return redirect("profile") else: form = UserForm(instance=request.user) data = {"user": request.user, "form": form, "scores": scores, 'match_leader': match_leader, 'snake_leader': snake_leader, 'match_avg': match_avg, 'snake_avg': snake_avg} return render(request, "profile.html", data)