def find_users(self, request, queryset):
for author in queryset.all():
if author.user:
continue
try:
author.user = User.objects.get(username=author.login)
except User.DoesNotExist:
pass
if not author.user:
author.user = User.objects.filter(email=author.email).first()
if not author.user:
author.user = User.objects.filter(first_name=author.first_name, last_name=author.last_name).first()
if author.user:
author.save()
self.message_user(
request,
_('Successfully found user {} for author').format(author.user, author),
messages.SUCCESS)
else:
self.message_user(request, _('Failed to find user for author {}').format(author), messages.ERROR)
评论列表
文章目录