Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关注页分页bug #25

Open
amchii opened this issue Jun 22, 2019 · 1 comment
Open

关注页分页bug #25

amchii opened this issue Jun 22, 2019 · 1 comment

Comments

@amchii
Copy link

amchii commented Jun 22, 2019

{% if follows|length != 1 %}

程序设置每页展示20用户,当关注数为21时第2页的follows|length为1,却被这个if给过滤掉了。
还有用户初始化时会首先关注自己,当获取第一页关注用户时
pagination = user.followers.paginate(page, per_page)
会同时获取到自己,然后被
{% if follow.follower != user %}
这条语句过滤掉,这就导致第一页会只显示19个用户

@amchii
Copy link
Author

amchii commented Jun 22, 2019

尝试了几种方法,本想使用offset偏移掉第一个,但是发现会报这个错误: Query.order_by() being called on a Query which already has LIMIT or OFFSET applied , 根据提示发现需要使用from_self
pagination = user.following.offset(1).from_self().paginate(1,20),
更合理还是使用filter,可以通过filter过滤自己后再分页 ,比如
pagination = user.following.filter(Follow.followed_id != user.id).paginate(page=page, per_page=per_page)
最后{% if follows|length != 0 %} 就可以了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant