Add 'bot_banner' field to ProductModel and create BotProductDetailView for bot integration
This commit is contained in:
@@ -191,14 +191,14 @@ class ProductModelAdmin(ModelAdmin, ImportExportModelAdmin):
|
||||
inlines = [ProductVariantInLine]
|
||||
readonly_fields = ('slug', 'created_at')
|
||||
search_fields = ['name', 'description', ]
|
||||
list_filter = ['show', 'category']
|
||||
list_filter = ['show', 'category', 'show_in_bot']
|
||||
autocomplete_fields = ['related_products', 'shop']
|
||||
# compressed_fields = True
|
||||
warn_unsaved_form = True
|
||||
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', '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': ('rating', 'view',), "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='بنر ربات'),
|
||||
),
|
||||
]
|
||||
@@ -124,7 +124,7 @@ class ProductModel(models.Model):
|
||||
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='نمایش در ربات')
|
||||
|
||||
bot_banner = models.TextField(null=True, blank=True, verbose_name='بنر ربات')
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
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 = [
|
||||
path('slider_category', ShowCaseProductsView.as_view(), name='category-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('slider_categories', ShowCaseCategoryListView.as_view(), name='all-categories'),
|
||||
re_path(r'^comments/(?P<slug>[\w\u0600-\u06FF\-]+)$', CommentView.as_view(), name='comment-views'),
|
||||
|
||||
@@ -459,4 +459,14 @@ class BotProductsView(APIView):
|
||||
return Response({
|
||||
"success": False,
|
||||
"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}'
|
||||
})
|
||||
Reference in New Issue
Block a user