-
Notifications
You must be signed in to change notification settings - Fork 30
Ahmetbahadircol HW4 #96
base: main
Are you sure you want to change the base?
Conversation
ahmetbahadircol
commented
Dec 18, 2021
- Added register url to add anew User to Customers
- Customized password field in serilizer and viewset
- Basket.basket is blank=True now.
- Added add_product action endpoint
… now. Basket endpoint has not finished yet.
… to create new basket/basketitem
| Basket item model | ||
| """ | ||
| basket = models.ForeignKey(Basket, verbose_name=_("Basket"), on_delete=models.PROTECT) | ||
| basket = models.ForeignKey(Basket, verbose_name=_("Basket"), on_delete=models.PROTECT, blank=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.
basket neden blank olabilir dedik, boyle bir sey eklersek problem yasama ihtimalimiz cok buyuk olacaktir.
|
|
||
| def get_queryset(self): | ||
| queryset = super().get_queryset() | ||
| user = 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.
user.id eger None olursa ne yapmaliyiz? kod nasil davranmali?
|
|
||
| def get_queryset(self): | ||
| queryset = super().get_queryset() | ||
| user = 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.
user.id None olursa ne yapmaliyiz? kod nasil davranmali?
| customer_obj = Customer.objects.filter(id=user).first() | ||
| product = serializer.validated_data.get("product") | ||
| quantity = serializer.validated_data.get("quantity") | ||
| price = serializer.validated_data.get("price") |
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.
price degerini kullanicidan almak guzel bir fikir olmayacaktir.
| """ | ||
| serializer = BasketItemSerializer(data=request.data) | ||
| if serializer.is_valid(): | ||
| user = 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.
user.id None olursa ne yapmaliyiz? yani login olmayan bir kullanici durumunda ne yapmaliyiz?
| password2 = serializers.CharField(write_only=True, required=True) | ||
|
|
||
| def create(self, validated_data): | ||
| customer = Customer.objects.create( |
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.
customer olusturmak icin create_user seklinde guzel bir manager methodumuz var.
|
|
||
| return customer | ||
|
|
||
| def update(self, instance, validated_data): |
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.
register serializer'inin update i olmamali sanki?
| :return: Customer Object | ||
| """ | ||
| queryset = self.get_queryset() | ||
| filter_kwargs = {"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.
register isleminde login olmus bir kullaniciyi beklemek guzel bir fikir degil sanki?
| queryset = Customer.objects.all() | ||
| serializer_class = RegisterSerializer | ||
| permission_classes = () | ||
| http_method_names = ["get", "put", "patch", "options"] |
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.
mixins.CreateModelMixin post methodunu bekler, put ve patch icin bir mixin tanimi yapmamisiz ve esasinda gerek de yok diyebilirim, cunku sadece register yapmaya calisiyoruz.
| path('api/token/refresh/', TokenRefreshView.as_view(), name='token_refresh'), | ||
| path('api/profile/', MyProfileViewSet.as_view( | ||
| {"get": "retrieve", "put": "update", "patch": "partial_update"}), name='profile'), | ||
| path('api/register/', RegisterViewSet.as_view({"put": "create", "get": "retrieve"}), 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.
burada tanim yapacak isek RESTful standartlarinda create icin POST yapilmali. Fakat router'a register edilse daha iyi olur.
Register endpointi normal sartlarda get yanitina cevap vermemeli.