Add 'bot_banner' field to ProductModel and create BotProductDetailView for bot integration

This commit is contained in:
Parsa Nazer
2025-08-05 00:13:47 +03:30
parent d9b6655ee8
commit e9b1666423
5 changed files with 34 additions and 5 deletions
+2 -2
View File
@@ -191,14 +191,14 @@ class ProductModelAdmin(ModelAdmin, ImportExportModelAdmin):
inlines = [ProductVariantInLine] inlines = [ProductVariantInLine]
readonly_fields = ('slug', 'created_at') readonly_fields = ('slug', 'created_at')
search_fields = ['name', 'description', ] search_fields = ['name', 'description', ]
list_filter = ['show', 'category'] list_filter = ['show', 'category', 'show_in_bot']
autocomplete_fields = ['related_products', 'shop'] autocomplete_fields = ['related_products', 'shop']
# compressed_fields = True # compressed_fields = True
warn_unsaved_form = True warn_unsaved_form = True
actions_list = ['redirect_to_learn', 'update_products_price'] actions_list = ['redirect_to_learn', 'update_products_price']
list_display = ['display_image', 'display_price', 'view', 'show', 'rating', 'category', 'created_at'] list_display = ['display_image', 'display_price', 'view', 'show', 'rating', 'category', 'created_at']
fieldsets = ( fieldsets = (
('فیلد های اصلی', {'fields': ('name', 'description', 'category', 'related_products', 'show', 'shop', 'show_in_bot'), "classes": ["tab"],}), ('فیلد های اصلی', {'fields': ('name', 'description', 'category', 'related_products', 'show', 'shop', 'show_in_bot', 'bot_banner'), "classes": ["tab"],}),
('فیلد های سيو', {'fields': ('meta_description', 'meta_keywords', 'meta_rating', 'slug'), "classes": ["tab"],}), ('فیلد های سيو', {'fields': ('meta_description', 'meta_keywords', 'meta_rating', 'slug'), "classes": ["tab"],}),
('فیلد های مربوط به کاربر', {'fields': ('rating', 'view',), "classes": ["tab"],}), ('فیلد های مربوط به کاربر', {'fields': ('rating', 'view',), "classes": ["tab"],}),
# ('فیلد های ایتم های پک', {'fields': ('in_pack_items', ), "classes": ["tab"],}) # ('فیلد های ایتم های پک', {'fields': ('in_pack_items', ), "classes": ["tab"],})
@@ -0,0 +1,18 @@
# Generated by Django 5.1.2 on 2025-08-04 20:41
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('product', '0053_productmodel_show_in_bot'),
]
operations = [
migrations.AddField(
model_name='productmodel',
name='bot_banner',
field=models.TextField(blank=True, null=True, verbose_name='بنر ربات'),
),
]
+1 -1
View File
@@ -124,7 +124,7 @@ class ProductModel(models.Model):
related_products = models.ManyToManyField('self', blank=True, 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) 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='نمایش در ربات') show_in_bot = models.BooleanField(default=False, verbose_name='نمایش در ربات')
bot_banner = models.TextField(null=True, blank=True, verbose_name='بنر ربات')
def __str__(self): def __str__(self):
return self.name return self.name
+2 -1
View File
@@ -1,9 +1,10 @@
from django.urls import path, re_path from django.urls import path, re_path
from .views import AllCategories, ProductView, AllProductsView, CommentView, ShowCaseProductsView, ShowCaseCategoryListView, BotProductsView from .views import AllCategories, ProductView, AllProductsView, CommentView, ShowCaseProductsView, ShowCaseCategoryListView, BotProductsView,BotProductDetailView
urlpatterns = [ urlpatterns = [
path('slider_category', ShowCaseProductsView.as_view(), name='category-products'), path('slider_category', ShowCaseProductsView.as_view(), name='category-products'),
path('bot', BotProductsView.as_view(), name='bot-products'), path('bot', BotProductsView.as_view(), name='bot-products'),
path('bot/<int:pk>/', BotProductDetailView.as_view(), name='bot-product-detail'),
path('categories', AllCategories.as_view(), name='all-categories'), path('categories', AllCategories.as_view(), name='all-categories'),
path('slider_categories', ShowCaseCategoryListView.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'), re_path(r'^comments/(?P<slug>[\w\u0600-\u06FF\-]+)$', CommentView.as_view(), name='comment-views'),
+11 -1
View File
@@ -459,4 +459,14 @@ class BotProductsView(APIView):
return Response({ return Response({
"success": False, "success": False,
"products": [] "products": []
}) })
class BotProductDetailView(APIView):
def get(self, request, pk):
product = get_object_or_404(ProductModel, pk=pk, show_in_bot=True)
return Response({
'banner' : product.banner,
'link': f'https://heymlz.com/product/{product.slug}'
})