Heroku数据库不规范

时间:2017-04-17 14:14:00

标签: python django postgresql heroku

我正在使用PostGres Hobby Dev计划。我已经部署了我的Django应用程序(它是一个社交网络)。但是,当用户与应用程序交互时,例如,用户x跟随用户y。显然,这会更改数据库以记录x跟随y。

但是,当我查看个人资料页面时,有时会说x不跟随y。但是,如果我刷新页面,它会更改回x跟随y。

这是一个性能问题,因为我正处于业余爱好开发计划中吗?

由于

显示个人资料页面的视图位于下方。

    @login_required
    def profile_view(request, username):
        # following list for the logged in user
        logged_in_user_following_list = Follow.objects.following(request.user)
        other_user = User.objects.get(username__exact=username)

        # check if logged in user is following this user
        if other_user in logged_in_user_following_list:
            is_following = True
        else:
            is_following = False

        # if requested user is the one that is logged in, redirect to own profile page
        if username == request.user.username:
            is_own_account = True
        else:
            is_own_account = False

        user = get_object_or_404(User, username=username)

        # get feed for this user
        posts = Post.objects.select_related("user").filter(user=user)

        title = "Profile: " + user.username
        if request.method == 'POST':
            form = UploadProfileImageForm(request.POST, request.FILES)
            if form.is_valid():
                user_profile = request.user.profile
                # if an image already exists, delete it
                if user_profile.profile_image:
                    user_profile.profile_image.delete()

                image = form.cleaned_data['image']
                user_profile.profile_image = image
                user_profile.save()
                print("valid form")
                return redirect("accounts:profile", request.user.username)
        else:
            form = UploadProfileImageForm()
        # form = UploadProfileImageForm()

        email = user.email.strip().lower()
        hash = md5.new(email).hexdigest()
        return render(request, "accounts/personal_info.html", {
            'profile_user': user,
            "title": title,
            'is_following': is_following,
            'is_own_account': is_own_account,
            'following': Follow.objects.following(other_user),
            'followers': Follow.objects.followers(other_user),
            "hash": hash,
            "user": user,
            "form": form,
            "posts": posts,
        })

在模板中显示关注者的相关部分位于

之下
<p>
    <a href="{% url 'accounts:following' username=profile_user.username %}">Following: {{ following|length }}</a> |
    <a href="{% url 'accounts:followers' username=profile_user.username %}">Followers: {{ followers|length }}</a>
</p>

0 个答案:

没有答案