first commit
This commit is contained in:
101
settings/serializers.py
Normal file
101
settings/serializers.py
Normal file
@@ -0,0 +1,101 @@
|
||||
from rest_framework import serializers
|
||||
from django.conf import settings
|
||||
|
||||
# from product.models import Category, Product, Images, Tags
|
||||
from settings.models import Setting, SiteSettings
|
||||
|
||||
"""
|
||||
title
|
||||
content
|
||||
categories
|
||||
keywords
|
||||
brim
|
||||
price
|
||||
tags
|
||||
gallery
|
||||
images
|
||||
thumb
|
||||
video
|
||||
slug
|
||||
created_at
|
||||
updated_at
|
||||
is_active
|
||||
is_front
|
||||
"""
|
||||
|
||||
"""
|
||||
class CateSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Category
|
||||
fields = ['title', 'parent', 'is_active', 'created_at', 'order', 'slug', 'images', 'keywords', 'description']
|
||||
|
||||
|
||||
class GalSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Images
|
||||
fields = ['title', 'images']
|
||||
|
||||
|
||||
class TagSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Tags
|
||||
fields = ['tag', 'slug']
|
||||
|
||||
|
||||
class ProductSerializer(serializers.ModelSerializer):
|
||||
categories = CateSerializer(read_only=True, many=True)
|
||||
gallery = GalSerializer(read_only=True, many=True)
|
||||
tags = TagSerializer(read_only=True, many=True)
|
||||
|
||||
class Meta:
|
||||
model = Product
|
||||
fields = ['title', 'content', 'categories', 'keywords', 'brim', 'tags', 'gallery', 'images', 'thumb', 'video',
|
||||
'slug', 'created_at', 'updated_at', 'is_active', 'is_front','price']
|
||||
# fields = '__all__'
|
||||
|
||||
|
||||
class CategorySerializer(serializers.ModelSerializer):
|
||||
categories = ProductSerializer(read_only=True, many=True)
|
||||
child = serializers.SerializerMethodField()
|
||||
|
||||
class Meta:
|
||||
model = Category
|
||||
fields = ['title', 'parent', 'is_active', 'created_at', 'order', 'slug', 'images', 'keywords', 'description',
|
||||
'categories', 'child']
|
||||
|
||||
def get_child(self, obj):
|
||||
serializer = self.__class__(obj.child.all(), many=True, context=self.context)
|
||||
return serializer.data
|
||||
|
||||
"""
|
||||
|
||||
|
||||
class SettingSerializer(serializers.ModelSerializer):
|
||||
b_logo = serializers.SerializerMethodField()
|
||||
w_logo = serializers.SerializerMethodField()
|
||||
|
||||
class Meta:
|
||||
model = Setting
|
||||
fields = ['title', 'meta_title', 'meta_description', 'phone', 'url', 'email', 'facebook', 'x','pinterest','linkedin',
|
||||
'instagram', 'whatsapp', 'slogan', 'w_logo', 'b_logo', 'created_at',
|
||||
'updated_at', 'is_active']
|
||||
|
||||
def get_w_logo(self, obj):
|
||||
if obj.w_logo:
|
||||
# Sadece path döndür, domain olmadan
|
||||
return obj.w_logo.url
|
||||
return None
|
||||
|
||||
def get_b_logo(self, obj):
|
||||
if obj.b_logo:
|
||||
# Sadece path döndür, domain olmadan
|
||||
return obj.b_logo.url
|
||||
return None
|
||||
|
||||
|
||||
class SettingOpenCloseSerializer(serializers.ModelSerializer):
|
||||
|
||||
class Meta:
|
||||
model = SiteSettings
|
||||
fields = ['is_active','site_active']
|
||||
|
||||
Reference in New Issue
Block a user