This commit is contained in:
AmirHossein Shirazi
2024-12-13 11:27:30 +03:30
parent cabd3517ac
commit eef8263869
4 changed files with 37 additions and 6 deletions
+2 -1
View File
@@ -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/<int:pk>', views.CommentView.as_view(), name='comment-list'),
# path('comment/<int:pk>', views.CommentView.as_view(), name='comment-list'),
path('products/', include('product.urls')),
path('', SpectacularSwaggerView.as_view(url_name='schema'), name='swagger-ui'),
]
@@ -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'],
},
),
]
+1 -2
View File
@@ -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):
+3 -3
View File
@@ -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/<int:pk>', ProductView.as_view(), name='product-detail'),
path('categories/products', AllProductsView.as_view(), name='category-products'),
path('products/<int:pk>/comments', CommentView.as_view(), name='product-comments'),
path('<int:pk>', ProductView.as_view(), name='product-detail'),
path('<int:pk>/comments', CommentView.as_view(), name='product-comments'),
path('comments/<int:pk>', CommentView.as_view(), name='comment-delete'),
]