Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

comments app #11

Merged
merged 3 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added comments/__init__.py
Empty file.
9 changes: 9 additions & 0 deletions comments/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.contrib import admin

from .models import Comment


@admin.register(Comment)
class CommentAdmin(admin.ModelAdmin):
list_display = ("pk", "author", "text", "created_at")
list_filter = ("author", "created_at")
8 changes: 8 additions & 0 deletions comments/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.apps import AppConfig


class CommentsConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "comments"
verbose_name = "Комментарий"
verbose_name_plural = "Комментарии"
37 changes: 37 additions & 0 deletions comments/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from django.db import models
from ipr.models import IPR
from task.models import Task
from users.models import User

from core.enums import Limits


class Comment(models.Model):
author = models.ForeignKey(
User,
related_name="comments",
on_delete=models.CASCADE,
verbose_name="Автор комментария",
)
ipr = models.ForeignKey(
IPR,
related_name="comments",
on_delete=models.CASCADE,
verbose_name="ИПР",
)
task = models.ForeignKey(
Task,
related_name="comments",
on_delete=models.CASCADE,
verbose_name="Задача",
)

text = models.TextField(
verbose_name="Комментарий",
max_length=Limits.MAX_LEN_COMMENT_TEXT,
)

created_at = models.DateField(
auto_now_add=True,
verbose_name="Дата создания",
)
1 change: 1 addition & 0 deletions config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
]
LOCAL_APPS = [
"api.v1.apps.ApiConfig",
"comments.apps.CommentsConfig",
]
INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS

Expand Down
6 changes: 6 additions & 0 deletions core/enums.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from enum import IntEnum


class Limits(IntEnum):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это что?
Какую задачу решает?
Почему max_length это не константа в settings.py?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Коллекция перечислений.
Большой разницы нет, если не нужно перебирать или получить имя по значению.
Когда добавлял, ещё констант не было в settings.
Так код немного понятнее, на мой взгляд.
Импорт класса Limits более понятен, чем импорт settings и лаконичнее чем импорт констант из settings.
Удалю, перенесу константой в settings.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Я вроде разобрался, интересное решение.
Я бы попробовал, но переносить константы из settings уже лениво.
В идеале такое должно быть установлено как правильно на старте проекта.

PS: А почему в MAX_LEN_COMMENT_TEXT = (200,) 200 внутри кортежа?
На первый взгляд должно быть MAX_LEN_COMMENT_TEXT = 200

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

С кортежем, я ошибся.
Перенес константой в settings.

# Максимальная длина текстового поля комментария в приложении "comments"
MAX_LEN_COMMENT_TEXT = (200,)