diff --git a/core/apps/products/urls.py b/core/apps/products/urls.py index 9d455e1..8d9188f 100644 --- a/core/apps/products/urls.py +++ b/core/apps/products/urls.py @@ -18,4 +18,5 @@ urlpatterns = [ ] )), path('search/', search_views.SearchApiView.as_view()), + path('set_tg_id//', product_views.UpdateProductTgIdApiView.as_view()), ] \ No newline at end of file diff --git a/core/apps/products/views/product.py b/core/apps/products/views/product.py index 6d4de0c..a99ff2d 100644 --- a/core/apps/products/views/product.py +++ b/core/apps/products/views/product.py @@ -1,6 +1,6 @@ from django.shortcuts import get_object_or_404 -from rest_framework import generics +from rest_framework import generics, views from rest_framework.response import Response from core.apps.products.models import Product, Category @@ -46,4 +46,12 @@ class ProductDetailApiView(generics.GenericAPIView): def get(self, request, id): product = get_object_or_404(Product, id=id) serializer = self.serializer_class(product) - return Response(serializer.data, status=200) \ No newline at end of file + return Response(serializer.data, status=200) + + +class UpdateProductTgIdApiView(views.APIView): + def post(self, request, product_code): + product = get_object_or_404(Product, code=product_code) + product.tg_id = request.data.get('tg_id') + product.save() + return Response({'success': True, 'message': 'telegram id saqlandi'}, status=200) \ No newline at end of file