Skip to content

Commit

Permalink
add level property in Profile & add in Profile view
Browse files Browse the repository at this point in the history
  • Loading branch information
tkdwns414 committed Aug 17, 2023
1 parent 2097f13 commit b0b1897
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
6 changes: 6 additions & 0 deletions accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ class Profile(BaseModel):
info = models.JSONField(default={})
completed_cnt = models.IntegerField(default=0)

@property
def level(self):
level = self.completed_cnt // 3 + 1
level = 5 if (level > 5) else level
return level


class ProfileReport(ReportBaseModel):
profile = models.ForeignKey(
Expand Down
2 changes: 2 additions & 0 deletions accounts/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Meta:
"type",
"user_id",
"joined_at",
"level",
]
read_only_fields = [
"id",
Expand All @@ -29,6 +30,7 @@ class Meta:
"completed_cnt",
"type",
"user_id",
"level",
]

def get_following_cnt(self, instance):
Expand Down
7 changes: 1 addition & 6 deletions core/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@ class WriterSerializer(serializers.ModelSerializer):
profile_id = serializers.IntegerField(source="profile.id")
nickname = serializers.CharField(source="profile.nickname")
type = serializers.CharField(source="profile.type")
level = serializers.SerializerMethodField(read_only=True)

def get_level(self, instance):
level = instance.profile.completed_cnt // 3 + 1
level = 5 if (level > 5) else level
return level
level = serializers.IntegerField(source="profile.level")

class Meta:
model = User
Expand Down

0 comments on commit b0b1897

Please sign in to comment.