From 1662f8b9404330ada5a1aefdedf30bb81cf735d8 Mon Sep 17 00:00:00 2001 From: ganesh Date: Mon, 24 Oct 2016 14:13:17 +0530 Subject: [PATCH] fixes --- project_template/reviews/serializers.py | 13 +++++++++++++ project_template/reviews/views.py | 10 ++++++++-- .../staticfiles/src/myapps/cars/controllers.js | 2 +- .../src/myapps/cars/review/car_review.html | 9 +++++---- .../src/myapps/cars/review/controller.js | 2 +- .../staticfiles/src/myapps/cars/services.js | 2 +- .../staticfiles/src/myapps/cars/templates/home.html | 4 ++-- 7 files changed, 31 insertions(+), 11 deletions(-) diff --git a/project_template/reviews/serializers.py b/project_template/reviews/serializers.py index 2c8c204..bc1fd85 100644 --- a/project_template/reviews/serializers.py +++ b/project_template/reviews/serializers.py @@ -46,6 +46,19 @@ def get_image(self, obj): return str(obj.variant.image) class CarVariantSerializer(serializers.ModelSerializer): + car_reviews = serializers.SerializerMethodField() + variant_name = serializers.SerializerMethodField() + class Meta: model = CarVariant + + def get_car_reviews(self, obj): + return_data = [] + for reviews in obj.carvariantreview_set.all(): + return_data.append(reviews.review) + return return_data + + def get_variant_name(self, obj): + return "%s %s %s" %(obj.brand.name, obj.model.name, obj.name) + diff --git a/project_template/reviews/views.py b/project_template/reviews/views.py index 3b52eba..72caa64 100644 --- a/project_template/reviews/views.py +++ b/project_template/reviews/views.py @@ -84,10 +84,16 @@ class CarVariantView(CarVariantMixin, generics.RetrieveUpdateDestroyAPIView): class CarVariantsReviewView(generics.ListCreateAPIView): permission_classes = (IsAuthenticatedOrReadOnly,) - queryset = CarVariantReview.objects.all() serializer_class = CarVariantReviewSerializer - + def get_queryset(self, *args, **kwargs): + # import ipdb; ipdb.set_trace() + try : + variant_id = self.request.GET['variant'] + return CarVariantReview.objects.filter(variant=variant_id) + except : + return CarVariantReview.objects.all() + def perform_create(self, serializer): user = self.request.user serializer.save(review_by=user) diff --git a/project_template/staticfiles/src/myapps/cars/controllers.js b/project_template/staticfiles/src/myapps/cars/controllers.js index 0d3efde..db1d993 100644 --- a/project_template/staticfiles/src/myapps/cars/controllers.js +++ b/project_template/staticfiles/src/myapps/cars/controllers.js @@ -21,7 +21,7 @@ // ****************************** // Internal methods // ****************************** - carsService.getAllCars().then(function(response){ + carsService.getAllVariants().then(function(response){ $scope.newCars = response.data; }).catch(function() { $scope.error = 'unable to get the cars'; diff --git a/project_template/staticfiles/src/myapps/cars/review/car_review.html b/project_template/staticfiles/src/myapps/cars/review/car_review.html index 8bd7e7a..fb61dad 100644 --- a/project_template/staticfiles/src/myapps/cars/review/car_review.html +++ b/project_template/staticfiles/src/myapps/cars/review/car_review.html @@ -10,15 +10,16 @@ - +

Rating

Review

- -

{{carReview.review}}

-

{{vm.car.review}}

+
+

{{review.review}}

+
+

{{review}}