“Wagtail CMS:如何按最后登录时间排序用户”

huangapple go评论54阅读模式
英文:

wagtail cms: how to sort users by last login

问题

要在后台(菜单 > 设置 > 用户)按最后登录时间对用户进行排序,我(以及我的客户)想要默认只能按姓名和用户名排序。解决这个问题的最佳实践是什么?另外,在版本5中我没有找到这个功能。

英文:

I(and my customer) want to sort users in the backend (menu > settings > users) by last login. By default I'm only able to sort by name and by username. What is the best practice to solve that? Also in version 5 I did not found this function.

答案1

得分: 1

你可以查看用户索引视图 https://github.com/wagtail/wagtail/blob/main/wagtail/users/views/users.py#L67。然后你可以这样做:

在某处创建一个子类:

from wagtail.users.views.users import Index

class UserIndex(Index):
    def get_valid_orderings(self):
        return super().get_valid_orderings() + ["last_login"]

然后在 https://github.com/wagtail/wagtail/blob/main/wagtail/users/urls/users.py 上进行相关的urlpatterns修补:

from django.urls import path
from wagtail.users.urls.users import urlpatterns
from some.path import UserIndex

urlpatterns[0] = path("", UserIndex.as_view(), name="index")

据我所知,wagtail并没有提供一种像常见的Django管理界面那样轻松配置或适应其管理视图的方式。不过,你可以很容易地添加新的视图。

英文:

You can look at the User index view https://github.com/wagtail/wagtail/blob/main/wagtail/users/views/users.py#L67. Then you can do this quick and dirty:

Subclass it (somewhere):

from wagtail.users.views.users import Index

class UserIndex(Index):
    def get_valid_orderings(self):
        return super().get_valid_orderings() + ["last_login"]

And monkey-patch the relevant urlpatterns at https://github.com/wagtail/wagtail/blob/main/wagtail/users/urls/users.py

from django.urls import path
from wagtail.users.urls.users import urlpatterns
from some.path import UserIndex

urlpatterns[0] = path("", UserIndex.as_view(), name="index")

AFAIK, wagtail does not provide an easy way to configure or adapt its admin views like the common django admin. You can easily add new ones, though.

huangapple
  • 本文由 发表于 2023年5月15日 15:52:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/76251935.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定