Add 'show_in_bot' field to ProductModel and implement BotProductsView for bot integration
This commit is contained in:
@@ -198,7 +198,7 @@ class ProductModelAdmin(ModelAdmin, ImportExportModelAdmin):
|
||||
actions_list = ['redirect_to_learn', 'update_products_price']
|
||||
list_display = ['display_image', 'display_price', 'view', 'show', 'rating', 'category', 'created_at']
|
||||
fieldsets = (
|
||||
('فیلد های اصلی', {'fields': ('name', 'description', 'category', 'related_products', 'show', 'shop'), "classes": ["tab"],}),
|
||||
('فیلد های اصلی', {'fields': ('name', 'description', 'category', 'related_products', 'show', 'shop', 'show_in_bot'), "classes": ["tab"],}),
|
||||
('فیلد های سيو', {'fields': ('meta_description', 'meta_keywords', 'meta_rating', 'slug'), "classes": ["tab"],}),
|
||||
('فیلد های مربوط به کاربر', {'fields': ('rating', 'view',), "classes": ["tab"],}),
|
||||
# ('فیلد های ایتم های پک', {'fields': ('in_pack_items', ), "classes": ["tab"],})
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 5.1.2 on 2025-08-04 19:44
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('product', '0052_productmodel_shop'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='productmodel',
|
||||
name='show_in_bot',
|
||||
field=models.BooleanField(default=False, verbose_name='نمایش در ربات'),
|
||||
),
|
||||
]
|
||||
@@ -123,7 +123,7 @@ class ProductModel(models.Model):
|
||||
category = models.ForeignKey(SubCategoryModel, null=True, on_delete=models.SET_NULL, related_name='products', verbose_name='دسته بندی محصول')
|
||||
related_products = models.ManyToManyField('self', blank=True, verbose_name='محصولات مرتبط')
|
||||
shop = models.ForeignKey('account.ShopModel', on_delete=models.CASCADE, related_name='products', verbose_name='فروشگاه', blank=True, null=True)
|
||||
|
||||
show_in_bot = models.BooleanField(default=False, verbose_name='نمایش در ربات')
|
||||
|
||||
|
||||
def __str__(self):
|
||||
|
||||
@@ -176,3 +176,12 @@ class CommentSerializer(serializers.ModelSerializer):
|
||||
exclude = ('review_status', )
|
||||
read_only_fields = ('review_status', 'product', 'user')
|
||||
|
||||
|
||||
|
||||
class BotProductSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = ProductModel
|
||||
fields = [
|
||||
'pk',
|
||||
'name'
|
||||
]
|
||||
@@ -1,8 +1,9 @@
|
||||
from django.urls import path, re_path
|
||||
from .views import AllCategories, ProductView, AllProductsView, CommentView, ShowCaseProductsView, ShowCaseCategoryListView
|
||||
from .views import AllCategories, ProductView, AllProductsView, CommentView, ShowCaseProductsView, ShowCaseCategoryListView, BotProductsView
|
||||
|
||||
urlpatterns = [
|
||||
path('slider_category', ShowCaseProductsView.as_view(), name='category-products'),
|
||||
path('bot', BotProductsView.as_view(), name='bot-products'),
|
||||
path('categories', AllCategories.as_view(), name='all-categories'),
|
||||
path('slider_categories', ShowCaseCategoryListView.as_view(), name='all-categories'),
|
||||
re_path(r'^comments/(?P<slug>[\w\u0600-\u06FF\-]+)$', CommentView.as_view(), name='comment-views'),
|
||||
|
||||
@@ -429,3 +429,34 @@ class CommentView(APIView):
|
||||
return Response({"detail": "شما اجازه ی پاک کردن این کامنت را ندارید"}, status=status.HTTP_403_FORBIDDEN)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.views import APIView
|
||||
from rest_framework import serializers
|
||||
from .models import ProductModel
|
||||
|
||||
class BotProductSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = ProductModel
|
||||
fields = ['pk', 'name']
|
||||
|
||||
class BotProductsView(APIView):
|
||||
serializer_class = BotProductSerializer
|
||||
|
||||
def get(self, request):
|
||||
bot_products = ProductModel.objects.filter(show_in_bot=True)
|
||||
|
||||
if bot_products.exists():
|
||||
serialized = self.serializer_class(bot_products, many=True)
|
||||
return Response({
|
||||
"success": True,
|
||||
"products": serialized.data
|
||||
})
|
||||
else:
|
||||
return Response({
|
||||
"success": False,
|
||||
"products": []
|
||||
})
|
||||
Reference in New Issue
Block a user