This commit is contained in:
marzban-dev
2025-08-31 17:57:05 +03:30
15 changed files with 18172 additions and 9 deletions
@@ -0,0 +1,28 @@
# Generated by Django 5.1.2 on 2025-08-02 15:21
import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('account', '0028_newsmodel_is_read'),
]
operations = [
migrations.CreateModel(
name='ShopModel',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('shop_name', models.CharField(max_length=100, verbose_name='نام فروشگاه')),
('shop_description', models.TextField(verbose_name='توضیحات فروشگاه')),
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='shop', to=settings.AUTH_USER_MODEL, verbose_name='کاربر')),
],
options={
'verbose_name': 'فروشگاه',
'verbose_name_plural': 'فروشگاه ها',
},
),
]
+14
View File
@@ -120,6 +120,20 @@ class User(AbstractBaseUser, PermissionsMixin):
return self.phone
class ShopModel(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE, related_name='shop', verbose_name='کاربر')
shop_name = models.CharField(max_length=100, verbose_name='نام فروشگاه')
shop_description = models.TextField(verbose_name='توضیحات فروشگاه')
def __str__(self):
return f"{self.user.phone} - {self.shop_name}"
class Meta:
verbose_name = 'فروشگاه'
verbose_name_plural = 'فروشگاه ها'
class UserAddressModel(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='address', verbose_name='کاربر')
name = models.CharField(max_length=30, verbose_name='نام ادرس')
+5
View File
@@ -107,6 +107,11 @@ UNFOLD = {
"link": reverse_lazy("admin:order_ordermodel_changelist"),
"badge": "utils.admin.admin_pending_count",
},
{
"title": _("فروشگاه ها"),
"icon": "storefront",
"link": reverse_lazy("admin:account_shopmodel_changelist"),
},
],
},
+15 -3
View File
@@ -41,6 +41,18 @@ class InPackItemsAdmin(ModelAdmin, ImportExportModelAdmin):
"widget": ArrayWidget,
}
}
from account.models import ShopModel
@admin.register(ShopModel)
class ShopModelAdmin(ModelAdmin, ImportExportModelAdmin):
search_fields = ['name']
compressed_fields = True
warn_unsaved_form = True
formfield_overrides = {
ArrayField: {
"widget": ArrayWidget,
}
}
class AttributeValueInLine(StackedInline):
@@ -179,14 +191,14 @@ class ProductModelAdmin(ModelAdmin, ImportExportModelAdmin):
inlines = [ProductVariantInLine]
readonly_fields = ('slug', 'created_at')
search_fields = ['name', 'description', ]
list_filter = ['show', 'category']
autocomplete_fields = ['related_products', ]
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',), "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-07-23 15:52
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('product', '0048_productvariant_created_at'),
]
operations = [
migrations.AlterField(
model_name='productmodel',
name='slug',
field=models.SlugField(allow_unicode=True, blank=True, help_text='این فیلد را خالی بگذارید', max_length=255, null=True, unique=True, verbose_name='نام یکتا'),
),
]
@@ -0,0 +1,152 @@
# Generated by Django 5.1.2 on 2025-07-28 11:44
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('home', '0018_remove_showcaseslider_image_and_more'),
('product', '0049_alter_productmodel_slug'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.AddIndex(
model_name='commentmodel',
index=models.Index(fields=['product'], name='comment_product_idx'),
),
migrations.AddIndex(
model_name='commentmodel',
index=models.Index(fields=['review_status'], name='comment_review_status_idx'),
),
migrations.AddIndex(
model_name='commentmodel',
index=models.Index(fields=['product', 'review_status'], name='comment_product_status_idx'),
),
migrations.AddIndex(
model_name='commentmodel',
index=models.Index(fields=['user'], name='comment_user_idx'),
),
migrations.AddIndex(
model_name='commentmodel',
index=models.Index(fields=['timestamp'], name='comment_timestamp_idx'),
),
migrations.AddIndex(
model_name='detailmodel',
index=models.Index(fields=['detail_model'], name='detail_model_idx'),
),
migrations.AddIndex(
model_name='detailmodel',
index=models.Index(fields=['title'], name='detail_title_idx'),
),
migrations.AddIndex(
model_name='dollormodel',
index=models.Index(fields=['unique_filed'], name='dollor_unique_field_idx'),
),
migrations.AddIndex(
model_name='maincategorymodel',
index=models.Index(fields=['slug'], name='main_category_slug_idx'),
),
migrations.AddIndex(
model_name='productdetailcategory',
index=models.Index(fields=['title'], name='detail_category_title_idx'),
),
migrations.AddIndex(
model_name='productdetailmodel',
index=models.Index(fields=['detail_category'], name='product_detail_category_idx'),
),
migrations.AddIndex(
model_name='productmodel',
index=models.Index(fields=['slug'], name='product_slug_idx'),
),
migrations.AddIndex(
model_name='productmodel',
index=models.Index(fields=['category'], name='product_category_idx'),
),
migrations.AddIndex(
model_name='productmodel',
index=models.Index(fields=['name'], name='product_name_idx'),
),
migrations.AddIndex(
model_name='productmodel',
index=models.Index(fields=['created_at'], name='product_created_at_idx'),
),
migrations.AddIndex(
model_name='productmodel',
index=models.Index(fields=['show'], name='product_show_idx'),
),
migrations.AddIndex(
model_name='productmodel',
index=models.Index(fields=['category', 'created_at'], name='product_category_created_idx'),
),
migrations.AddIndex(
model_name='productmodel',
index=models.Index(fields=['category', 'name'], name='product_category_name_idx'),
),
migrations.AddIndex(
model_name='productvariant',
index=models.Index(fields=['product', 'price', 'created_at'], name='idx_product_price_created'),
),
migrations.AddIndex(
model_name='productvariant',
index=models.Index(fields=['in_stock', 'discount'], name='idx_stock_discount'),
),
migrations.AddIndex(
model_name='productvariant',
index=models.Index(fields=['created_at'], name='idx_created'),
),
migrations.AddIndex(
model_name='productvariant',
index=models.Index(fields=['price'], name='idx_price'),
),
migrations.AddIndex(
model_name='productvariant',
index=models.Index(fields=['discount'], name='product_variant_discount_idx'),
),
migrations.AddIndex(
model_name='productvariant',
index=models.Index(fields=['in_stock'], name='product_variant_in_stock_idx'),
),
migrations.AddIndex(
model_name='productvariant',
index=models.Index(fields=['product'], name='product_variant_product_idx'),
),
migrations.AddIndex(
model_name='productvariant',
index=models.Index(fields=['slider_category'], name='variant_slider_category_idx'),
),
migrations.AddIndex(
model_name='productvariant',
index=models.Index(fields=['slider_category', 'in_stock'], name='variant_slider_stock_idx'),
),
migrations.AddIndex(
model_name='productvariant',
index=models.Index(fields=['slider_category', 'discount'], name='variant_slider_discount_idx'),
),
migrations.AddIndex(
model_name='productvariant',
index=models.Index(fields=['slider_category', 'created_at'], name='variant_slider_created_idx'),
),
migrations.AddIndex(
model_name='productvariant',
index=models.Index(fields=['product', 'in_stock'], name='variant_product_stock_idx'),
),
migrations.AddIndex(
model_name='productvariant',
index=models.Index(fields=['product', 'discount'], name='variant_product_discount_idx'),
),
migrations.AddIndex(
model_name='productvariant',
index=models.Index(fields=['currency'], name='variant_currency_idx'),
),
migrations.AddIndex(
model_name='subcategorymodel',
index=models.Index(fields=['slug'], name='sub_category_slug_idx'),
),
migrations.AddIndex(
model_name='subcategorymodel',
index=models.Index(fields=['parent'], name='sub_category_parent_idx'),
),
]
@@ -0,0 +1,33 @@
# Generated by Django 5.1.2 on 2025-08-02 15:21
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('product', '0050_commentmodel_comment_product_idx_and_more'),
]
operations = [
migrations.RemoveIndex(
model_name='productvariant',
name='variant_slider_category_idx',
),
migrations.RemoveIndex(
model_name='productvariant',
name='variant_slider_stock_idx',
),
migrations.RemoveIndex(
model_name='productvariant',
name='variant_slider_discount_idx',
),
migrations.RemoveIndex(
model_name='productvariant',
name='variant_slider_created_idx',
),
migrations.RemoveIndex(
model_name='productvariant',
name='variant_currency_idx',
),
]
@@ -0,0 +1,20 @@
# Generated by Django 5.1.2 on 2025-08-02 15:23
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('account', '0029_shopmodel'),
('product', '0051_remove_productvariant_variant_slider_category_idx_and_more'),
]
operations = [
migrations.AddField(
model_name='productmodel',
name='shop',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='products', to='account.shopmodel', verbose_name='فروشگاه'),
),
]
@@ -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='نمایش در ربات'),
),
]
@@ -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='بنر ربات'),
),
]
+53 -5
View File
@@ -17,6 +17,9 @@ class MainCategoryModel(models.Model):
class Meta:
verbose_name = "دسته‌بندی اصلی"
verbose_name_plural = "دسته‌بندی‌هااصلی"
indexes = [
models.Index(fields=['slug'], name='main_category_slug_idx'),
]
def __str__(self):
return self.name
@@ -39,6 +42,10 @@ class SubCategoryModel(models.Model):
class Meta:
verbose_name = "زیر دسته‌بندی"
verbose_name_plural = "زیر دسته‌بندی‌ها"
indexes = [
models.Index(fields=['slug'], name='sub_category_slug_idx'),
models.Index(fields=['parent'], name='sub_category_parent_idx'),
]
def __str__(self):
return self.name
@@ -84,6 +91,9 @@ class DollorModel(models.Model):
class Meta:
verbose_name = 'مدل دلار'
verbose_name_plural = 'مدل دلار'
indexes = [
models.Index(fields=['unique_filed'], name='dollor_unique_field_idx'),
]
class InPackItems(models.Model):
@@ -104,7 +114,7 @@ class ProductModel(models.Model):
rating = models.PositiveIntegerField(default=0, verbose_name='امتیاز')
show = models.BooleanField(default=False, verbose_name='نمایش در خانه')
view = models.IntegerField(default=0, verbose_name='بازدید')
slug = models.SlugField(max_length=50, unique=True, blank=True, null=True, allow_unicode=True,
slug = models.SlugField(max_length=255, unique=True, blank=True, null=True, allow_unicode=True,
verbose_name='نام یکتا', help_text="این فیلد را خالی بگذارید")
meta_description = models.CharField(max_length=300, blank=True, null=True, help_text='این فیلد را حتما پر کنید', verbose_name='متا دیسکریپشن')
meta_keywords = models.CharField(max_length=300, blank=True, null=True, help_text='این فیلد را حتما پر کنید', verbose_name='متا کیورد')
@@ -112,9 +122,9 @@ class ProductModel(models.Model):
created_at = models.DateTimeField(auto_now_add=True, verbose_name='زمان ثبت محصول')
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='نمایش در ربات')
bot_banner = models.TextField(null=True, blank=True, verbose_name='بنر ربات')
def __str__(self):
return self.name
@@ -127,6 +137,16 @@ class ProductModel(models.Model):
class Meta:
verbose_name = 'محصول'
verbose_name_plural = 'محصولات'
ordering = ['category', 'name']
indexes = [
models.Index(fields=['slug'], name='product_slug_idx'),
models.Index(fields=['category'], name='product_category_idx'),
models.Index(fields=['name'], name='product_name_idx'),
models.Index(fields=['created_at'], name='product_created_at_idx'),
models.Index(fields=['show'], name='product_show_idx'),
models.Index(fields=['category', 'created_at'], name='product_category_created_idx'),
models.Index(fields=['category', 'name'], name='product_category_name_idx'),
]
@@ -140,7 +160,10 @@ class ProductDetailCategory(models.Model):
class Meta:
verbose_name = 'دسته بندی جزيات'
verbose_name_plural = 'دسته بندی های جزيیات'
verbose_name_plural = 'دسته بندی های جزيیات'
indexes = [
models.Index(fields=['title'], name='detail_category_title_idx'),
]
@@ -162,6 +185,13 @@ class CommentModel(models.Model):
class Meta:
verbose_name = 'نظر'
verbose_name_plural = 'نظرات'
indexes = [
models.Index(fields=['product'], name='comment_product_idx'),
models.Index(fields=['review_status'], name='comment_review_status_idx'),
models.Index(fields=['product', 'review_status'], name='comment_product_status_idx'),
models.Index(fields=['user'], name='comment_user_idx'),
models.Index(fields=['timestamp'], name='comment_timestamp_idx'),
]
def __str__(self):
return f"{self.user}-{self.content[:30]}"
@@ -205,6 +235,9 @@ class ProductDetailModel(models.Model):
class Meta:
verbose_name = 'جزیات محصول'
verbose_name_plural = 'جزیات محصول ها'
indexes = [
models.Index(fields=['detail_category'], name='product_detail_category_idx'),
]
def __str__(self):
return f'جزيیات محصول {self.detail_category.title} - {self.name}'
@@ -222,6 +255,10 @@ class DetailModel(models.Model):
class Meta:
verbose_name = 'مدل جزیات'
verbose_name_plural = 'مدل های جزیات'
indexes = [
models.Index(fields=['detail_model'], name='detail_model_idx'),
models.Index(fields=['title'], name='detail_title_idx'),
]
class ProductVariant(models.Model):
@@ -250,6 +287,17 @@ class ProductVariant(models.Model):
class Meta:
verbose_name = 'تنوع محصول'
verbose_name_plural = 'تنوع‌های محصول'
indexes = [
models.Index(fields=['product', 'price', 'created_at'], name='idx_product_price_created'),
models.Index(fields=['in_stock', 'discount'], name='idx_stock_discount'),
models.Index(fields=['created_at'], name='idx_created'),
models.Index(fields=['price'], name='idx_price'),
models.Index(fields=['discount'], name='product_variant_discount_idx'),
models.Index(fields=['in_stock'], name='product_variant_in_stock_idx'),
models.Index(fields=['product'], name='product_variant_product_idx'),
models.Index(fields=['product', 'in_stock'], name='variant_product_stock_idx'),
models.Index(fields=['product', 'discount'], name='variant_product_discount_idx'),
]
def __str__(self):
return f"{self.product.name} - {', '.join(str(attr) for attr in self.product_attributes.all())}"
+9
View File
@@ -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'
]
+3 -1
View File
@@ -1,8 +1,10 @@
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,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'),
+43
View File
@@ -219,6 +219,7 @@ class AllProductsView(APIView):
products = products.order_by('name')
# Pagination
products.order_by('category')
paginator = self.pagination_class()
paginated_products = paginator.paginate_queryset(products, request)
serializer = self.serializer_class(
@@ -429,3 +430,45 @@ 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": []
})
class BotProductDetailView(APIView):
def get(self, request, pk):
product = get_object_or_404(ProductModel, pk=pk, show_in_bot=True)
return Response({
'name': product.name,
'banner' : product.bot_banner,
'link': f'https://heymlz.com/product/{product.slug}'
})
+17743
View File
File diff suppressed because it is too large Load Diff