add: add laguage to unity
This commit is contained in:
@@ -7,5 +7,5 @@ class CategorySerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Category
|
||||
fields = [
|
||||
'id', 'name'
|
||||
'id', 'name_uz', 'name_ru', 'image'
|
||||
]
|
||||
|
||||
@@ -7,7 +7,7 @@ class ProductListSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Product
|
||||
fields = [
|
||||
'id', 'name', 'image', 'category', 'price', 'description', 'unity'
|
||||
'id', 'name_uz', 'name_ru', 'image', 'category', 'price', 'description_uz', 'description_ru', 'unity'
|
||||
]
|
||||
|
||||
def get_category(self, obj):
|
||||
@@ -17,9 +17,10 @@ class ProductListSerializer(serializers.ModelSerializer):
|
||||
}
|
||||
|
||||
|
||||
class ProductCreateSerializer(serializers.ModelSerializer):
|
||||
class ProductSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Product
|
||||
fields = [
|
||||
'name', 'image', 'category', 'price', 'description', 'unity'
|
||||
]
|
||||
'name_uz', 'name_ru', 'image', 'category', 'price', 'description_uz', 'description_ru', 'unity'
|
||||
]
|
||||
|
||||
|
||||
@@ -7,5 +7,5 @@ class UnitySerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Unity
|
||||
fields = [
|
||||
'id', 'name'
|
||||
'id', 'name_uz', 'name_ru'
|
||||
]
|
||||
@@ -4,6 +4,7 @@ from core.apps.admin_panel.views import user as user_views
|
||||
from core.apps.admin_panel.views import banner as banner_views
|
||||
from core.apps.admin_panel.views import unity as unity_views
|
||||
from core.apps.admin_panel.views import category as category_views
|
||||
from core.apps.admin_panel.views import product as product_views
|
||||
|
||||
|
||||
|
||||
@@ -44,4 +45,12 @@ urlpatterns = [
|
||||
path('<uuid:id>/delete/', category_views.CategoryDeleteApiView.as_view()),
|
||||
]
|
||||
)),
|
||||
path('product/', include(
|
||||
[
|
||||
path('create/', product_views.ProductCreateApiView.as_view()),
|
||||
path('list/', product_views.ProductListApiView.as_view()),
|
||||
# path('<uuid:id>/update/', product_views..as_view()),
|
||||
path('<uuid:id>/delete/', product_views.ProductDeleteApiView.as_view()),
|
||||
]
|
||||
)),
|
||||
]
|
||||
@@ -1,6 +1,6 @@
|
||||
from django.shortcuts import get_object_or_404
|
||||
|
||||
from rest_framework import generics, views, permissions, status
|
||||
from rest_framework import generics, views, permissions, status, parsers
|
||||
|
||||
from core.apps.shared.mixins.response import ResponseMixin
|
||||
from core.apps.products.models import Category
|
||||
@@ -23,6 +23,7 @@ class CategoryCreateApiView(generics.GenericAPIView, ResponseMixin):
|
||||
serializer_class = CategorySerializer
|
||||
queryset = Category.objects.all()
|
||||
permission_classes = [permissions.IsAdminUser]
|
||||
parser_classes = [parsers.FormParser, parsers.MultiPartParser]
|
||||
|
||||
def post(self, request):
|
||||
serializer = self.serializer_class(data=request.data)
|
||||
@@ -51,6 +52,7 @@ class CategoryUpdateApiView(generics.GenericAPIView, ResponseMixin):
|
||||
serializer_class = CategorySerializer
|
||||
queryset = Category.objects.all()
|
||||
permission_classes = [permissions.IsAdminUser]
|
||||
parser_classes = [parsers.FormParser, parsers.MultiPartParser]
|
||||
|
||||
def patch(self, request, id):
|
||||
category = get_object_or_404(Category, id=id)
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
from rest_framework import generics, views
|
||||
from django.shortcuts import get_object_or_404
|
||||
|
||||
from rest_framework import generics, views, status, parsers
|
||||
from rest_framework.permissions import IsAdminUser
|
||||
|
||||
from core.apps.admin_panel.serializers import product as serializers
|
||||
@@ -18,6 +20,48 @@ class ProductListApiView(generics.GenericAPIView):
|
||||
return self.get_paginated_response(serializer.data)
|
||||
|
||||
|
||||
# class ProductCreateApiView(generics.GenericAPIView, ResponseMixin):
|
||||
class ProductCreateApiView(generics.GenericAPIView, ResponseMixin):
|
||||
serializer_class = serializers.ProductSerializer
|
||||
queryset = Product.objects.all()
|
||||
permission_classes = [IsAdminUser]
|
||||
parser_classes = [parsers.FormParser, parsers.MultiPartParser]
|
||||
|
||||
def post(self, request):
|
||||
serializer = self.serializer_class(data=request.data)
|
||||
if serializer.is_valid(raise_exception=True):
|
||||
serializer.save()
|
||||
return self.success_response(
|
||||
message='mahsulot qoshildi', status_code=status.HTTP_201_CREATED
|
||||
)
|
||||
return self.failure_response(message='mahsulot qoshishda hatolik', data=serializer.errors)
|
||||
|
||||
|
||||
class ProductDeleteApiView(generics.GenericAPIView, ResponseMixin):
|
||||
serializer_class = None
|
||||
queryset = Product.objects.all()
|
||||
permission_classes = [IsAdminUser]
|
||||
|
||||
def delete(self, request, id):
|
||||
product = get_object_or_404(Product, id=id)
|
||||
product.delete()
|
||||
return self.success_response(
|
||||
message='product deleted', status_code=status.HTTP_204_NO_CONTENT
|
||||
)
|
||||
|
||||
|
||||
class ProductUpdateApiView(generics.GenericAPIView, ResponseMixin):
|
||||
serializer_class = serializers.ProductSerializer
|
||||
queryset = Product.objects.all()
|
||||
permission_classes = [IsAdminUser]
|
||||
parser_classes = [parsers.FormParser, parsers.MultiPartParser]
|
||||
|
||||
def patch(self, request, id):
|
||||
product = get_object_or_404(Product, id=id)
|
||||
serializer = self.serializer_class(data=request.data, instance=product)
|
||||
if serializer.is_valid(raise_exception=True):
|
||||
serializer.save()
|
||||
return self.success_response(
|
||||
message='mahsulot tahrirlandi',
|
||||
)
|
||||
return self.failure_response(message='mahsulot tahrirlashda hatolik', data=serializer.errors)
|
||||
|
||||
@@ -12,5 +12,5 @@ class ProductAdmin(TranslationAdmin):
|
||||
|
||||
|
||||
@admin.register(Unity)
|
||||
class UnityAdmin(admin.ModelAdmin):
|
||||
class UnityAdmin(TranslationAdmin):
|
||||
list_display = ['id', 'name']
|
||||
@@ -0,0 +1,23 @@
|
||||
# Generated by Django 5.2 on 2025-09-03 15:40
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('products', '0003_unity_product_unity'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='unity',
|
||||
name='name_ru',
|
||||
field=models.CharField(max_length=200, null=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='unity',
|
||||
name='name_uz',
|
||||
field=models.CharField(max_length=200, null=True),
|
||||
),
|
||||
]
|
||||
@@ -1,10 +1,17 @@
|
||||
from modeltranslation import translator
|
||||
|
||||
from core.apps.products.models import Product
|
||||
from core.apps.products.models import Product, Unity
|
||||
|
||||
|
||||
@translator.register(Product)
|
||||
class ProductTranslation(translator.TranslationOptions):
|
||||
fields = [
|
||||
'name', 'description'
|
||||
]
|
||||
|
||||
|
||||
@translator.register(Unity)
|
||||
class UnityTranslation(translator.TranslationOptions):
|
||||
fields = [
|
||||
'name'
|
||||
]
|
||||
Reference in New Issue
Block a user