Add video field to MainCategoryModel and update related serializers and views
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
from django.shortcuts import render, get_object_or_404, redirect
|
||||
from rest_framework.views import APIView, Response
|
||||
from product.models import ProductModel, SubCategoryModel, DollorModel
|
||||
from product.serializers import SubCategorySerializer, DynamicProductSerializer
|
||||
from product.models import ProductModel, SubCategoryModel, MainCategoryModel
|
||||
from product.serializers import SubCategorySerializer, DynamicProductSerializer, MainCategorySerializer
|
||||
from .serializers import *
|
||||
from .models import *
|
||||
from rest_framework import status
|
||||
@@ -24,8 +24,8 @@ class HomeView(APIView):
|
||||
sliders = SliderModel.objects.all()
|
||||
slider_ser = SliderSerializer(instance=sliders, many=True, context={'request': request})
|
||||
|
||||
sub_categories = SubCategoryModel.objects.filter(show=True)
|
||||
sub_category_ser = SubCategorySerializer(instance=sub_categories, many=True, context={'request': request})
|
||||
main_categories = MainCategoryModel.objects.all()
|
||||
main_category_ser = MainCategorySerializer(instance=main_categories, many=True, context={'request': request})
|
||||
|
||||
products_to_show = ProductModel.objects.filter(show=True)
|
||||
product_ser = DynamicProductSerializer(instance=products_to_show, many=True, context={'request': request, 'view_type': 'list'})
|
||||
@@ -38,7 +38,7 @@ class HomeView(APIView):
|
||||
|
||||
response = {
|
||||
'sliders': slider_ser.data,
|
||||
'sub_categories': sub_category_ser.data,
|
||||
'main_categories': main_category_ser.data,
|
||||
'products': product_ser.data,
|
||||
'difreance_section': home_image_ser.data,
|
||||
'show_case_slider': show_cases_ser.data
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 5.1.2 on 2025-05-21 11:19
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('product', '0045_remove_subcategorymodel_show_maincategorymodel_image'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='maincategorymodel',
|
||||
name='video',
|
||||
field=models.FileField(blank=True, null=True, upload_to='product_videos/', verbose_name='ویدیو'),
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 5.1.2 on 2025-05-21 11:20
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('product', '0046_maincategorymodel_video'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='maincategorymodel',
|
||||
name='video',
|
||||
field=models.FileField(blank=True, null=True, upload_to='category_videos/', verbose_name='ویدیو'),
|
||||
),
|
||||
]
|
||||
@@ -13,7 +13,7 @@ class MainCategoryModel(models.Model):
|
||||
image = models.ImageField(upload_to='category_model/',verbose_name='عکس', blank=True, null=True)
|
||||
meta_title = models.CharField(max_length=60, verbose_name="عنوان متا", help_text="عنوان متا برای SEO", blank=True, null=True)
|
||||
meta_description = models.TextField(max_length=160, verbose_name="توضیحات متا", help_text="توضیحات متا برای SEO", blank=True, null=True)
|
||||
|
||||
video = models.FileField(upload_to='category_videos/', blank=True, null=True, verbose_name='ویدیو')
|
||||
class Meta:
|
||||
verbose_name = "دستهبندی اصلی"
|
||||
verbose_name_plural = "دستهبندیهااصلی"
|
||||
|
||||
@@ -103,7 +103,7 @@ class MainCategorySerializer(serializers.ModelSerializer):
|
||||
subcategorys = SubCategorySerializer(many=True)
|
||||
class Meta:
|
||||
model = MainCategoryModel
|
||||
fields = ['id', 'name', 'slug', 'icon', 'meta_title', 'meta_description', 'subcategorys', 'image']
|
||||
fields = ['id', 'name', 'slug', 'icon', 'meta_title', 'meta_description', 'subcategorys', 'image', 'video']
|
||||
|
||||
|
||||
class DynamicProductSerializer(serializers.ModelSerializer):
|
||||
|
||||
Reference in New Issue
Block a user