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

Feature/reviews #5

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open

Feature/reviews #5

wants to merge 2 commits into from

Conversation

DKlimovskiy
Copy link
Collaborator

No description provided.

Дмитрий Климовский added 2 commits April 11, 2023 20:34
Copy link
Owner

@smart2004 smart2004 left a comment

Choose a reason for hiding this comment

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

В общем что мог написал, и посмотри плиз мое предложение по Review и Category

)
]

def get_rating(self, obj):
Copy link
Owner

Choose a reason for hiding this comment

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

Про рейтинг ты интересовался..

Получается по факту, что пользователь приходит и просто здесь проставляет оценку, которая в review имеет поле/field 'score', ее не нужно усреднять, он ставит 1 оценку. (т.к. эта часть приходится на мою в Titles. Там считается rating avg по оценкам пользователей:
<rating = serializers.IntegerField(
source='reviews__score__avg', read_only=True)>

То что у тебя округление до 2го знака после точки (что так можно я совсем недавно узнал)



urlpatterns = [
# path('v1/', include('djoser.urls')),
# path('v1/', include('djoser.urls.jwt')),
path('v1/', include('djoser.urls')),
Copy link
Owner

Choose a reason for hiding this comment

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

из-за 23, 24 не нужны

path('v1/', include(router.urls)),
# path('v1/auth/signup/', register, name='register'),
# path('v1/auth/token/', get_jwt_token, name='token')
# path('v1/auth/signup/', register, name='register'),
Copy link
Owner

Choose a reason for hiding this comment

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

26, 27 будем использовать

serializer.save(author=self.request.user)
title_id = self.request.data.get('title')
reviews = Review.objects.filter(title_id=title_id)
rating = reviews.aggregate(Avg('score'))['score__avg']
Copy link
Owner

Choose a reason for hiding this comment

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

rating здесь не нужно высчитывать, только score вносить нужно 1 - 10. Считаем в ReadOnlyTitleSerializer (в моем куске кода)

class ReviewViewSet(viewsets.ModelViewSet):
queryset = Review.objects.all()
serializer_class = ReviewSerializer
permission_classes = (IsOwnerOrReadOnly, IsAuthenticatedOrReadOnly,)
Copy link
Owner

Choose a reason for hiding this comment

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

Вместо таких классов разрешений возможно IsAdminModeratorOrReadonly больше подходит


def perform_create(self, serializer):
serializer.save(author=self.request.user)
title_id = self.request.data.get('title')
Copy link
Owner

Choose a reason for hiding this comment

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

в ветке которую предложил я это по другому сделано(плиз посмотри)

title_id = self.request.data.get('title')
reviews = Review.objects.filter(title_id=title_id)
rating = reviews.aggregate(Avg('score'))['score__avg']
Title.objects.filter(id=title_id).update(rating=rating)
Copy link
Owner

Choose a reason for hiding this comment

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

это сделано у меня в ReadOnlyTitleSerializer,

queryset = Review.objects.all()
serializer_class = ReviewSerializer
permission_classes = (IsOwnerOrReadOnly, IsAuthenticatedOrReadOnly,)
authentication_classes = [JWTAuthentication]
Copy link
Owner

Choose a reason for hiding this comment

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

не совсем понимаю что это дает


class CommentViewSet(viewsets.ModelViewSet):
serializer_class = CommentSerializer
permission_classes = (IsOwnerOrReadOnly, IsAuthenticatedOrReadOnly,)
Copy link
Owner

Choose a reason for hiding this comment

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

IsAdminModeratorOwnerOrReadOnly

class CommentViewSet(viewsets.ModelViewSet):
serializer_class = CommentSerializer
permission_classes = (IsOwnerOrReadOnly, IsAuthenticatedOrReadOnly,)
authentication_classes = [JWTAuthentication]
Copy link
Owner

Choose a reason for hiding this comment

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

думаю это не нужно

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.

None yet

2 participants