1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| # 使用interest.category.all() 直接使用interest.category则会导致报错 @list_route() def recommendations(self, request): queryset = self.get_queryset()
if request.auth: interests = request.user.interests interest = interests.last() if interests.exists() else None categories = [item for item in interest.category.all() ] if interest else None
queryset = queryset.filter( category__in=categories) if categories else queryset
queryset = queryset.order_by('?')[:4] return PageResponse(self, queryset, FlowerSerializer)
|