-
Notifications
You must be signed in to change notification settings - Fork 30
Eylultuncel homework 4 #98
base: main
Are you sure you want to change the base?
Conversation
|
|
||
| def get_queryset(self): | ||
| queryset = super().get_queryset() | ||
| user_id = self.request.user.id |
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.
login olmamis bir user yoksa, burada bir problem olusuyor sanki?
|
|
||
|
|
||
| class BasketViewSet(DetailedViewSetMixin, viewsets.ModelViewSet): | ||
| 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.
| def get_queryset(self): | ||
| queryset = super().get_queryset() | ||
| user = self.request.user | ||
| return queryset.filter(customer=user) |
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.
ayni sekilde login olmamis bir kullanici yoksa problem olusuyor sanki.
| quantity = request.data["quantity"] | ||
| price = product.price | ||
| try: | ||
| basket = Basket.objects.get(customer__id=user_id, status="open") |
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.
model objelerini kullanmak yerine serializerlari kullanmak daha iyi fikir.
| basket.save() | ||
| basket_item.save() | ||
|
|
||
| serializer = BasketItemSerializer(basket_item) |
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.
basketviewseti basket'e ait bir serializer'i donmesi daha uyumlu olacaktir.
No description provided.