如何编辑Django Admin用户社交认证列表页面



我很难找到这个管理文件的存在位置,所以我可以添加一个额外的字段。我认为它是在设置时自动神奇地创建的。

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

django用户社交认证列表页面截图

好吧,这是我尝试使用Django allauth的内容,我认为它在某种程度上与Django sociallauth相同。只需获得想法的要点,并将其应用于您的代码

首先在您的任何admin.py文件中扩展SocialAccountAdmin,如果是在特定的应用程序中,如">user"、">主页或您喜欢的任何应用程序,效果会更好。

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

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

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

最新更新