You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

20 lines
596 B

from rest_framework import serializers
from library.models import Article
class ArticleSerializer(serializers.ModelSerializer):
tags = serializers.SerializerMethodField()
section = serializers.SerializerMethodField()
class Meta:
model = Article
exclude = ('css', 'js', 'page', 'head_title', 'public',
'head_description', 'head_image', 'id',)
@staticmethod
def get_tags(self):
return [i.name for i in self.tags.all()]
@staticmethod
def get_section(self):
return self.section.name if self.section else 'undefined'