Skip to content

Commit fe7ab85

Browse files
committed
update: 세션 목록에 누락된 필드 추가
1 parent ea0dc62 commit fe7ab85

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

accounts/serializers.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
11
from django.contrib.auth import get_user_model
22

33
import rest_framework.serializers as serializers
4+
from accounts.models import UserExt
45

56
User = get_user_model()
67

78

8-
class UserSerializer(serializers.ModelSerializer):
9+
class UserExtSerializer(serializers.ModelSerializer):
910
nickname = serializers.SerializerMethodField()
10-
bio = serializers.SerializerMethodField()
1111

1212
class Meta:
13-
model = User
13+
model = UserExt
1414
fields = [
1515
"nickname",
16-
"bio"
16+
"bio",
17+
"profile_img",
1718
]
1819

1920
@staticmethod
20-
def get_nickname(obj: User):
21-
return "{}{}".format(obj.last_name, obj.first_name)
22-
23-
@staticmethod
24-
def get_bio(obj: User):
25-
return obj.userext.bio
21+
def get_nickname(obj: UserExt):
22+
return "{}{}".format(obj.user.last_name, obj.user.first_name)

program/serializers.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from rest_framework import serializers
22

33
from program.models import Proposal, ProposalCategory
4-
from accounts.serializers import UserSerializer
4+
from accounts.serializers import UserExtSerializer
55

66

77
class ProposalSerializer(serializers.ModelSerializer):
@@ -34,7 +34,7 @@ class Meta:
3434

3535
def to_representation(self, instance: Proposal):
3636
response = super().to_representation(instance)
37-
response["user"] = UserSerializer(instance.user).data
37+
response["user"] = UserExtSerializer(instance.user.userext).data
3838
return response
3939

4040
@staticmethod
@@ -43,6 +43,8 @@ def get_category_name(obj: Proposal):
4343

4444

4545
class ProposalListSerializer(serializers.ModelSerializer):
46+
category_name = serializers.SerializerMethodField()
47+
4648
class Meta:
4749
model = Proposal
4850
fields = [
@@ -53,12 +55,22 @@ class Meta:
5355
"duration",
5456
"language",
5557
"category",
58+
"category_name",
5659
]
5760

5861
@staticmethod
5962
def get_profile_img(obj: Proposal):
6063
return obj.user.userext.profile_img
6164

65+
@staticmethod
66+
def get_category_name(obj: Proposal):
67+
return obj.category.name
68+
69+
def to_representation(self, instance: Proposal):
70+
response = super().to_representation(instance)
71+
response["user"] = UserExtSerializer(instance.user.userext).data
72+
return response
73+
6274

6375
class ProposalCategorySerializer(serializers.ModelSerializer):
6476
class Meta:

0 commit comments

Comments
 (0)