Django many-to-many model DRF

前端 未结 5 1613
执念已碎
执念已碎 2021-01-26 04:37

I have the following model structure:

class Project(models.Model):
  author = models.ManyToManyField(Account)
  name = models.CharField(max_length=40, default=\'         


        
5条回答
  •  情书的邮戳
    2021-01-26 05:32

    You need to set many=True when dealing with multiple relation - either a m2m or a reversed FK:

    author = AccountSerializer(read_only=True, required=False, many=True)
    

提交回复
热议问题