django rest框架中的嵌套关系存在一些问题
我的 models.py
function populateForm() {
var form = FormApp.openById('Id of your form');
form.setDestination(FormApp.DestinationType.SPREADSHEET, spreadsheet.getId());
var item = form.addCheckboxItem();
form.addMultipleChoiceItem()
.setTitle('What is your phone model?')
.setChoiceValues([('iPhone 6', 'iPhone 5', ...])
form.addMultipleChoiceItem()
.setTitle('What is your phone capacity?')
.setChoiceValues([('32GB', '64GB', ...])
...
}
serializers.py
class Category(models.Model):
category = models.CharField(max_length=128)
profile = models.ForeignKey(Profile, on_delete=models.CASCADE)
def __str__(self):
return self.category
class Interest(models.Model):
name= models.CharField(max_length=250, default='')
category = models.ForeignKey(Category, on_delete=models.CASCADE)
profile = models.ForeignKey(Profile, related_name='category_profiles', on_delete=models.CASCADE)
def __str__(self):
return self.name
当我在类别集中获取个人资料时,视图中的
为空
Form Service References for Apps Script
但是如果我在浏览器中单独显示它,则会显示正确的内容
现在,这就是我所拥有的。如何在个人资料中设置适当的类别?预先谢谢你!答案 0 :(得分:0)
您尚未指定概要文件序列化程序应序列化的字段列表。它是空的。
在您的ProfileSerializer中执行此操作
class ProfileSerializer(serializers.ModelSerializer):
category_set = CategorySerializer(many=True)
class Meta:
model = Profile
fields = ( 'category_set', )