From eef8263869883882a8913b3724f6be3b7756274a Mon Sep 17 00:00:00 2001 From: AmirHossein Shirazi Date: Fri, 13 Dec 2024 11:27:30 +0330 Subject: [PATCH] bug fixs --- backend/core/urls.py | 3 +- .../product/migrations/0005_categorymodel.py | 31 +++++++++++++++++++ backend/product/serializers.py | 3 +- backend/product/urls.py | 6 ++-- 4 files changed, 37 insertions(+), 6 deletions(-) create mode 100644 backend/product/migrations/0005_categorymodel.py diff --git a/backend/core/urls.py b/backend/core/urls.py index 96a51a9..931c2b0 100644 --- a/backend/core/urls.py +++ b/backend/core/urls.py @@ -16,7 +16,8 @@ urlpatterns = [ path('token/refresh/', TokenRefreshView.as_view(), name='token_refresh'), path('admin/', admin.site.urls), path('schema/', SpectacularAPIView.as_view(), name='schema'), - path('comment/', views.CommentView.as_view(), name='comment-list'), + # path('comment/', views.CommentView.as_view(), name='comment-list'), + path('products/', include('product.urls')), path('', SpectacularSwaggerView.as_view(url_name='schema'), name='swagger-ui'), ] diff --git a/backend/product/migrations/0005_categorymodel.py b/backend/product/migrations/0005_categorymodel.py new file mode 100644 index 0000000..5454b90 --- /dev/null +++ b/backend/product/migrations/0005_categorymodel.py @@ -0,0 +1,31 @@ +# Generated by Django 5.1.2 on 2024-12-13 07:51 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('product', '0004_rename_product_productmodel'), + ] + + operations = [ + migrations.CreateModel( + name='CategoryModel', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=50, verbose_name='نام دسته\u200cبندی')), + ('slug', models.SlugField(help_text='اسم دسته را برای مسیر به انگلیسی و بدون فاصله وارد کنید', unique=True)), + ('icon', models.CharField(blank=True, max_length=100, null=True, verbose_name='آیکون دسته\u200cبندی')), + ('meta_title', models.CharField(blank=True, help_text='عنوان متا برای SEO', max_length=60, null=True, verbose_name='عنوان متا')), + ('meta_description', models.TextField(blank=True, help_text='توضیحات متا برای SEO', max_length=160, null=True, verbose_name='توضیحات متا')), + ('parent', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='children', to='product.categorymodel', verbose_name='دسته\u200cبندی والد')), + ], + options={ + 'verbose_name': 'دسته\u200cبندی', + 'verbose_name_plural': 'دسته\u200cبندی\u200cها', + 'ordering': ['parent__id', 'id'], + }, + ), + ] diff --git a/backend/product/serializers.py b/backend/product/serializers.py index 507eafb..7abf8ee 100644 --- a/backend/product/serializers.py +++ b/backend/product/serializers.py @@ -5,7 +5,6 @@ class ProductSerializer(serializers.ModelSerializer): class Meta: model = ProductModel fields = "__all__" - read_only_fields = "__all__" class CommentSerializer(serializers.ModelSerializer): @@ -19,7 +18,7 @@ class CategorySerializer(serializers.ModelSerializer): children = serializers.SerializerMethodField() class Meta: - model = Category + model = CategoryModel fields = ['id', 'name', 'slug', 'icon', 'meta_title', 'meta_description', 'parent', 'children'] def get_children(self, obj): diff --git a/backend/product/urls.py b/backend/product/urls.py index cb733e3..c7787e9 100644 --- a/backend/product/urls.py +++ b/backend/product/urls.py @@ -2,9 +2,9 @@ from django.urls import path from .views import AllCategories, ProductView, AllProductsView, CommentView urlpatterns = [ + path('', AllProductsView.as_view(), name='category-products'), path('categories', AllCategories.as_view(), name='all-categories'), - path('products/', ProductView.as_view(), name='product-detail'), - path('categories/products', AllProductsView.as_view(), name='category-products'), - path('products//comments', CommentView.as_view(), name='product-comments'), + path('', ProductView.as_view(), name='product-detail'), + path('/comments', CommentView.as_view(), name='product-comments'), path('comments/', CommentView.as_view(), name='comment-delete'), ] \ No newline at end of file