• 许多托曼类外地 显示所有权,而不是在django休息室做假
模型
class Category(models.Model):
title = models.CharField(max_length=50)
slug = models.SlugField(max_length=50,null=False, unique=True)
def __str__(self):
return self.title
class BlogPostModel(models.Model):
author = models.ForeignKey(User, on_delete=models.CASCADE,null=True,blank=True)
category = models.ManyToManyField(Category, related_name= catitems )
title = models.CharField(max_length=255)
body = models.TextField()
slug = models.SlugField(max_length=255,null=False, unique=True)
background_image = models.ImageField(upload_to= post-images ,blank=True)
image1 = models.ImageField(upload_to= post-images ,blank=True)
image2 = models.ImageField(upload_to= post-images ,blank=True)
created_date = models.DateTimeField(auto_now_add=True)
def __str__(self):
return self.title
i 想要显示类别的所有权而不是类别补贴
航天员
class Post航天员(serializers.Model航天员):
author = serializers.CharField(source= author.email , read_only=True)
class Meta:
model = BlogPostModel
fields = [ author , category , title , body , slug , background_image , created_date ]
这是我的产物:
"category": [
1,
2,
3
],
并希望:
"category": [
Category title(1)،
Category title(2)،
Category title(3)
],