-
Notifications
You must be signed in to change notification settings - Fork 30
ToygarAksoy-homework4 #93
base: main
Are you sure you want to change the base?
Conversation
|
|
||
| basket = self.get_object() | ||
| try: | ||
| product = Product.objects.get(id=request.data["product"]) |
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.
request.data'yı serialize edip kullansak daha iyi olabilir.
bu çekleri serializerda yapmış oluruz.
| class BasketViewSet(DetailedViewSetMixin, viewsets.ModelViewSet): | ||
| # lookup_field = 'basket' | ||
| permission_classes = () | ||
| http_method_names = ["get", "delete"] |
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.
basketi kullaniciya sildirmek guzel bir fikir olmayabilir.
| user = self.request.user | ||
| basket_items_list = self.get_queryset().filter( | ||
| customer__id=user.id).first().basketitem_set.all() | ||
| serializer = self.get_serializer(basket_items_list, many=True) |
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.
burada basketitem serializer'inin datasini donmek guzel bir fikir olmayabilir, ilgili viewset kendi modeline ait serializer'i donmesi daha iyi olacaktir.
|
|
||
| @action(detail=True, methods=['post'], http_method_names=['post']) | ||
| @atomic() | ||
| def add_basket_item(self, request, pk=None): |
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.
tum bu methoddaki kayit islemlerini, validationlari serializer'a yaptirmak daha iyi olacaktir.
No description provided.