-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: develop
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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): |
There was a problem hiding this comment.
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')), |
There was a problem hiding this comment.
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'), |
There was a problem hiding this comment.
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'] |
There was a problem hiding this comment.
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,) |
There was a problem hiding this comment.
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') |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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] |
There was a problem hiding this comment.
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,) |
There was a problem hiding this comment.
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] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
думаю это не нужно
No description provided.