相关疑难解决方法(0)

Django REST Framework的AttributeError和ManyToMany关系

试图访问我的json页面我收到此错误!

AttributeError at /project/api/1.json
Got AttributeError when attempting to get a value for field `title` on serializer `TaskSerializer`.
The serializer field might be named incorrectly and not match any attribute or key on the `RelatedManager` instance.
Original exception text was: 'RelatedManager' object has no attribute 'title'.
Run Code Online (Sandbox Code Playgroud)

我和我的模特有很多关系:

class Project(models.Model):
    owner = models.ForeignKey('auth.User')
    title = models.CharField(max_length=100)
    slug = models.SlugField(unique=True)
    created_date = models.DateTimeField(auto_now_add=True, auto_now=False)
    updated_date = models.DateTimeField(auto_now_add=False, auto_now=True)

    def __str__(self):
        return self.title

    def save(self, **kwargs):
        super(Project, self, **kwargs).save()
        self.slug = slugify(self.title)
        super(Project, …
Run Code Online (Sandbox Code Playgroud)

python django many-to-many django-rest-framework

4
推荐指数
1
解决办法
6588
查看次数