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.
29 lines
771 B
29 lines
771 B
from rest_framework import serializers |
|
from article.models import Article |
|
from user_info.serializers import UserDescSerializer |
|
|
|
|
|
# 返回文章列表或创建一篇文章 |
|
class ArticleListSerializer(serializers.ModelSerializer): |
|
author = UserDescSerializer(read_only=True) |
|
# 使用article的url.py中的view --> detail |
|
url = serializers.HyperlinkedIdentityField(view_name="article:detail") |
|
|
|
class Meta: |
|
model = Article |
|
fields = [ |
|
'url', |
|
'title', |
|
'created', |
|
'body', |
|
'author', |
|
] |
|
# read_only_fields = ['author'] |
|
|
|
# 返回文章详情 |
|
|
|
|
|
class ArticleDetailSerializer(serializers.ModelSerializer): |
|
class Meta: |
|
model = Article |
|
fields = '__all__' |