Skip to content
This repository was archived by the owner on May 12, 2023. It is now read-only.

Conversation

@ahmetbahadircol
Copy link

  • 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

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)
Copy link
Owner

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
Copy link
Owner

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
Copy link
Owner

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")
Copy link
Owner

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
Copy link
Owner

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(
Copy link
Owner

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):
Copy link
Owner

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}
Copy link
Owner

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"]
Copy link
Owner

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')
Copy link
Owner

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants