From 41aa08beb0b4a056cfec4ffca55dc4851b930971 Mon Sep 17 00:00:00 2001 From: Injoon Hwang Date: Mon, 31 Jul 2023 11:59:23 +0000 Subject: [PATCH] refactor(model): use positive integer fields --- ..._count_alter_article_hit_count_and_more.py | 83 +++++++++++++++++++ apps/core/models/article.py | 18 ++-- apps/core/models/board.py | 2 +- apps/core/models/comment.py | 6 +- apps/user/models/user_profile.py | 6 +- 5 files changed, 100 insertions(+), 15 deletions(-) create mode 100644 apps/core/migrations/0056_alter_article_comment_count_alter_article_hit_count_and_more.py diff --git a/apps/core/migrations/0056_alter_article_comment_count_alter_article_hit_count_and_more.py b/apps/core/migrations/0056_alter_article_comment_count_alter_article_hit_count_and_more.py new file mode 100644 index 00000000..a99c5f8e --- /dev/null +++ b/apps/core/migrations/0056_alter_article_comment_count_alter_article_hit_count_and_more.py @@ -0,0 +1,83 @@ +# Generated by Django 4.2.3 on 2023-07-31 12:00 + +import apps.core.models.board +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("core", "0055_remove_board_group_id_board_group"), + ] + + operations = [ + migrations.AlterField( + model_name="article", + name="comment_count", + field=models.PositiveIntegerField(default=0, verbose_name="댓글 수"), + ), + migrations.AlterField( + model_name="article", + name="hit_count", + field=models.PositiveIntegerField(default=0, verbose_name="조회수"), + ), + migrations.AlterField( + model_name="article", + name="migrated_hit_count", + field=models.PositiveIntegerField(default=0, verbose_name="이전된 조회수"), + ), + migrations.AlterField( + model_name="article", + name="migrated_negative_vote_count", + field=models.PositiveIntegerField(default=0, verbose_name="이전된 싫어요 수"), + ), + migrations.AlterField( + model_name="article", + name="migrated_positive_vote_count", + field=models.PositiveIntegerField(default=0, verbose_name="이전된 좋아요 수"), + ), + migrations.AlterField( + model_name="article", + name="name_type", + field=models.PositiveSmallIntegerField( + default=apps.core.models.board.NameType["REGULAR"], + verbose_name="익명 혹은 실명 여부", + ), + ), + migrations.AlterField( + model_name="article", + name="negative_vote_count", + field=models.PositiveIntegerField(default=0, verbose_name="싫어요 수"), + ), + migrations.AlterField( + model_name="article", + name="positive_vote_count", + field=models.PositiveIntegerField(default=0, verbose_name="좋아요 수"), + ), + migrations.AlterField( + model_name="article", + name="report_count", + field=models.PositiveIntegerField(default=0, verbose_name="신고 수"), + ), + migrations.AlterField( + model_name="board", + name="top_threshold", + field=models.PositiveSmallIntegerField( + default=10, verbose_name="인기글 달성 기준 좋아요 개수" + ), + ), + migrations.AlterField( + model_name="comment", + name="negative_vote_count", + field=models.PositiveIntegerField(default=0, verbose_name="싫어요 수"), + ), + migrations.AlterField( + model_name="comment", + name="positive_vote_count", + field=models.PositiveIntegerField(default=0, verbose_name="좋아요 수"), + ), + migrations.AlterField( + model_name="comment", + name="report_count", + field=models.PositiveIntegerField(default=0, verbose_name="신고 수"), + ), + ] diff --git a/apps/core/models/article.py b/apps/core/models/article.py index d5f33c53..808f6058 100644 --- a/apps/core/models/article.py +++ b/apps/core/models/article.py @@ -49,7 +49,7 @@ class Article(MetaDataModel): verbose_name="text 형식 본문", editable=False, ) - name_type = models.SmallIntegerField( + name_type = models.PositiveSmallIntegerField( verbose_name="익명 혹은 실명 여부", default=NameType.REGULAR, ) @@ -61,35 +61,35 @@ class Article(MetaDataModel): verbose_name="정치/사회성 내용", default=False, ) - hit_count = models.IntegerField( + hit_count = models.PositiveIntegerField( verbose_name="조회수", default=0, ) - comment_count = models.IntegerField( + comment_count = models.PositiveIntegerField( verbose_name="댓글 수", default=0, ) - report_count = models.IntegerField( + report_count = models.PositiveIntegerField( verbose_name="신고 수", default=0, ) - positive_vote_count = models.IntegerField( + positive_vote_count = models.PositiveIntegerField( verbose_name="좋아요 수", default=0, ) - negative_vote_count = models.IntegerField( + negative_vote_count = models.PositiveIntegerField( verbose_name="싫어요 수", default=0, ) - migrated_hit_count = models.IntegerField( + migrated_hit_count = models.PositiveIntegerField( verbose_name="이전된 조회수", default=0, ) - migrated_positive_vote_count = models.IntegerField( + migrated_positive_vote_count = models.PositiveIntegerField( verbose_name="이전된 좋아요 수", default=0, ) - migrated_negative_vote_count = models.IntegerField( + migrated_negative_vote_count = models.PositiveIntegerField( verbose_name="이전된 싫어요 수", default=0, ) diff --git a/apps/core/models/board.py b/apps/core/models/board.py index 1fdb4716..45658b02 100644 --- a/apps/core/models/board.py +++ b/apps/core/models/board.py @@ -97,7 +97,7 @@ class Board(MetaDataModel): blank=True, default="", ) - top_threshold = models.SmallIntegerField( + top_threshold = models.PositiveSmallIntegerField( verbose_name="인기글 달성 기준 좋아요 개수", default=10, ) diff --git a/apps/core/models/comment.py b/apps/core/models/comment.py index cc2c84b3..f04735bf 100644 --- a/apps/core/models/comment.py +++ b/apps/core/models/comment.py @@ -45,15 +45,15 @@ class Meta(MetaDataModel.Meta): verbose_name="익명 혹은 실명", ) - report_count = models.IntegerField( + report_count = models.PositiveIntegerField( default=0, verbose_name="신고 수", ) - positive_vote_count = models.IntegerField( + positive_vote_count = models.PositiveIntegerField( default=0, verbose_name="좋아요 수", ) - negative_vote_count = models.IntegerField( + negative_vote_count = models.PositiveIntegerField( default=0, verbose_name="싫어요 수", ) diff --git a/apps/user/models/user_profile.py b/apps/user/models/user_profile.py index 37b25d46..ac1c1f19 100644 --- a/apps/user/models/user_profile.py +++ b/apps/user/models/user_profile.py @@ -74,7 +74,8 @@ class UserGroup(models.IntegerChoices): verbose_name="닉네임", ) nickname_updated_at = models.DateTimeField( - default=MIN_TIME, verbose_name="최근 닉네임 변경일시" + default=MIN_TIME, + verbose_name="최근 닉네임 변경일시", ) see_sexual = models.BooleanField( default=False, @@ -85,7 +86,8 @@ class UserGroup(models.IntegerChoices): verbose_name="정치/사회성 보기", ) group = models.IntegerField( - choices=UserGroup.choices, default=UserGroup.UNAUTHORIZED + choices=UserGroup.choices, + default=UserGroup.UNAUTHORIZED, ) user = models.OneToOneField( on_delete=models.CASCADE,