fix(pre-existing): FUser has no nickname field - use first_name (article notify, message sender_name, bug user_name)

This commit is contained in:
async-upgrade
2026-09-06 16:43:20 +08:00
parent d6e39ab976
commit e3d057dd54
3 changed files with 11 additions and 11 deletions
+2 -2
View File
@@ -330,7 +330,7 @@ class ArticleCommentListCreateView(generics.ListCreateAPIView):
parent_comment_id = comment.parent_id
parent_comment_user_id = comment.parent.user_id if comment.parent else None
user_id = request.user.id
user_nickname = request.user.nickname or request.user.username
user_nickname = request.user.first_name or request.user.username
transaction.on_commit(lambda: self._send_notification_messages(
article_id, article_title, article_author_id, comment_id,
@@ -455,7 +455,7 @@ class ArticleLikeToggleView(APIView):
recipient=article.author,
sender=request.user,
msg_type='like',
title=f'{request.user.nickname or request.user.username} 赞了你的文章',
title=f'{request.user.first_name or request.user.username} 赞了你的文章',
content=f'《{article.title}》',
extra_info='',
target_link=f'/article/{pk}',
+8 -8
View File
@@ -1,4 +1,4 @@
from adrf.serializers import (
from adrf.serializers import (
ModelSerializer, CharField, ImageField, DateTimeField,
ListField, FileField, SerializerMethodField,
)
@@ -34,7 +34,7 @@ class BugReportCommentAttachmentSerializer(ModelSerializer):
class BugReportCommentSerializer(ModelSerializer):
user_name = CharField(source='user.nickname', read_only=True)
user_name = CharField(source='user.first_name', read_only=True)
user_avatar = ImageField(source='user.avatar', read_only=True)
images = BugReportCommentImageSerializer(many=True, read_only=True)
attachments = BugReportCommentAttachmentSerializer(many=True, read_only=True)
@@ -50,7 +50,7 @@ class BugReportCommentSerializer(ModelSerializer):
class BugReportListSerializer(ModelSerializer):
user_name = CharField(source='user.nickname', read_only=True)
user_name = CharField(source='user.first_name', read_only=True)
images_count = SerializerMethodField()
class Meta:
@@ -65,7 +65,7 @@ class BugReportListSerializer(ModelSerializer):
class BugReportDetailSerializer(ModelSerializer):
user_name = CharField(source='user.nickname', read_only=True)
user_name = CharField(source='user.first_name', read_only=True)
user_avatar = ImageField(source='user.avatar', read_only=True)
images = BugReportImageSerializer(many=True, read_only=True)
attachments = BugReportAttachmentSerializer(many=True, read_only=True)
@@ -102,14 +102,14 @@ class BugReportCreateSerializer(ModelSerializer):
max_size = 10 * 1024 * 1024 # 10MB
for image in value:
if image.size > max_size:
raise ValidationError(f"图片 {image.name} 大小超过10MB限制")
raise ValidationError(f"鍥剧墖 {image.name} 澶у皬瓒呰繃10MB闄愬埗")
return value
def validate_attachments(self, value):
max_size = 20 * 1024 * 1024 # 20MB
for attachment in value:
if attachment.size > max_size:
raise ValidationError(f"附件 {attachment.name} 大小超过20MB限制")
raise ValidationError(f"闄勪欢 {attachment.name} 澶у皬瓒呰繃20MB闄愬埗")
return value
async def acreate(self, validated_data):
@@ -152,14 +152,14 @@ class BugReportCommentCreateSerializer(ModelSerializer):
max_size = 10 * 1024 * 1024 # 10MB
for image in value:
if image.size > max_size:
raise ValidationError(f"图片 {image.name} 大小超过10MB限制")
raise ValidationError(f"鍥剧墖 {image.name} 澶у皬瓒呰繃10MB闄愬埗")
return value
def validate_attachments(self, value):
max_size = 20 * 1024 * 1024 # 20MB
for attachment in value:
if attachment.size > max_size:
raise ValidationError(f"附件 {attachment.name} 大小超过20MB限制")
raise ValidationError(f"闄勪欢 {attachment.name} 澶у皬瓒呰繃20MB闄愬埗")
return value
async def acreate(self, validated_data):
+1 -1
View File
@@ -40,7 +40,7 @@ class MessageListSerializer(ModelSerializer):
async def get_sender_name(self, obj):
sender = await _load_sender(obj)
if sender:
return sender.nickname or sender.username
return sender.first_name or sender.username
return '系统'
async def get_sender_avatar(self, obj):