Skip to content

Моделька новостей#170

Merged
VeryBigSad merged 12 commits into
devfrom
feature/news
Jul 21, 2023
Merged

Моделька новостей#170
VeryBigSad merged 12 commits into
devfrom
feature/news

Conversation

@VeryBigSad
Copy link
Copy Markdown
Contributor

@VeryBigSad VeryBigSad commented Jul 18, 2023

Work in progress, пока что не мерджить

Нужно:

  • Сделать миграцию старых новостей в новые
  • Сделать вьюшки для новостей и проверить на локалхосте, что все работает
  • Убрать старую модельку (Может, потом?)

@yakser
Copy link
Copy Markdown
Member

yakser commented Jul 19, 2023

старую модельку точно лучше потом убрать

@yakser yakser self-requested a review July 19, 2023 10:46
Copy link
Copy Markdown
Member

@yakser yakser left a comment

Choose a reason for hiding this comment

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

в целом ок, но после дедлайна я бы порефакторил

Comment thread news/permissions.py
def has_permission(self, request, view):
"""
Creation permission
Currently can only be created via admin panel
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

проекты не только через админку, докстринг нужно поправить, а то непонятно)

Comment thread news/permissions.py

try:
# try to judge it as a project
project = Project.objects.get(pk=view.kwargs["project_pk"])
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

не лучше ли утащить эту логику в permissions проектов? если у нас будет 2-3 таких модельки то этот пермишн разростётся сильно

Comment thread news/views.py
permission_classes = [IsNewsCreatorOrReadOnly]
pagination_class = NewsPagination

def get(self, request, *args, **kwargs):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

а зачем вообще общая вьюшка новостей? они же отображаются по урлам в других приложениях

return News.objects.get_news(obj=program)

def get_queryset(self):
if self.kwargs.get("project_pk") is not None:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

выглядит странно) но пока что ок

Copy link
Copy Markdown
Member

@yakser yakser left a comment

Choose a reason for hiding this comment

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

надо пофиксить заколдованную миграцию

content_type=project_content_type,
object_id=project_news.project.id,
files=project_news.files.all(),
views=project_news.views.all(),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

У меня не работает и хз как эта штука работает в экшне. Мб стоит заменить get_model на обычны импорт (https://stackoverflow.com/questions/36256324/why-genericrelation-fields-does-not-work-in-data-migrationsdjango)
Но тогда проблема с files

text=project_news.text,
content_type=project_content_type,
object_id=project_news.project.id,
files=project_news.files.all(),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Use files.set() instead

@VeryBigSad VeryBigSad merged commit d210fc2 into dev Jul 21, 2023
@yakser yakser deleted the feature/news branch September 8, 2023 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants