【问题标题】:How to edit the Django Admin User social auths listing page?如何编辑 Django 管理员用户社交身份验证列表页面?
【发布时间】:2020-06-18 16:07:28
【问题描述】:

我无法找到此管理文件存在的位置,因此我可以添加一个额外的字段。我认为它是在设置时自动创建的。

我想在列表页面(如下所示)中添加一个日期字段,可能在 UID 字段之后,这样我就可以知道何时创建用户身份验证。

screenshot of django user social auths listing page

【问题讨论】:

标签: django django-admin django-socialauth


【解决方案1】:

好的,这就是我尝试使用 Django-allauth 的方法,我认为它与 django-socialauth 的工作方式相同。只需了解想法的要点并将其应用于您的代码即可

首先在您的任何 admin.py 文件中扩展 SocialAccountAdmin,最好在“user”、“home”等特定应用中",或者任何你喜欢的。

admin.py

from allauth.socialaccount.admin import SocialAccountAdmin
from allauth.socialaccount.models import SocialAccount

class MySocialAccount(SocialAccountAdmin):
    list_display = ('user', 'uid', 'provider', 'date_joined')  # I haven't tried just adding a certain list to the list_display, for the meantime add all necessary fields just like how socialauth did


admin.site.unregister(SocialAccount)  # Need to unregister the default socialaccount admin
admin.site.register(SocialAccount, MySocialAccount)  # Then register it back with the custom made admin

也许有更好的方法可以做到这一点,但这确实奏效了。

【讨论】:

    【解决方案2】:

    在模型中添加一个字段会很有趣吗?为您的创建日期添加一个 DateField。可能您需要了解更多信息:https://docs.djangoproject.com/en/3.0/ref/models/fields/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-11
      • 2019-07-16
      相关资源
      最近更新 更多