from django.contrib import admin

from .models import SocialApp, SocialAccount, SocialToken

from ..account import app_settings


class SocialAppAdmin(admin.ModelAdmin):
    list_display = ('name', 'provider',)
    filter_horizontal = ('sites',)


class SocialAccountAdmin(admin.ModelAdmin):
    if app_settings.USER_MODEL_USERNAME_FIELD:
        search_fields = ('user__' + app_settings.USER_MODEL_USERNAME_FIELD, )
    raw_id_fields = ('user',)
    list_display = ('user', 'uid', 'provider')
    list_filter = ('provider',)


class SocialTokenAdmin(admin.ModelAdmin):
    raw_id_fields = ('app', 'account',)
    list_display = ('app', 'account', 'truncated_token', 'expires_at')
    list_filter = ('app', 'app__provider', 'expires_at')

    def truncated_token(self, token):
        max_chars = 40
        ret = token.token
        if len(ret) > max_chars:
            ret = ret[0:max_chars] + '...(truncated)'
        return ret
    truncated_token.short_description = 'Token'

admin.site.register(SocialApp, SocialAppAdmin)
admin.site.register(SocialToken, SocialTokenAdmin)
admin.site.register(SocialAccount, SocialAccountAdmin)

@@ -121,16 +121,76 @@
 ettings%0A
+from ..utils import get_user_model%0A%0AUser = get_user_model()%0A
 %0A%0Aclass 
@@ -353,127 +353,283 @@
     
-if app_settings.USER_MODEL_USERNAME_FIELD:%0A        search_fields = ('user__' + app_settings.USER_MODEL_USERNAME_FIELD, 
+search_fields = %5B'user__emailaddress__email'%5D + %5C%0A        list(map(lambda a: 'user__' + a,%0A             filter(lambda a: a and hasattr(User(), a),%0A                   %5Bapp_settings.USER_MODEL_USERNAME_FIELD,%0A                    'first_name',%0A                    'last_name'%5D))
 )%0A  

Improve searching in SocialAccountAdmin.