Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django 1.8 KeyError: 'manager' on relationship

Tags:

I have models set up like this:

class Post(models.Model):     name = models.CharField(max_length=10)  class Comment(models.Model):     post = models.ForeignKey(Post,related_name='comments')     name = models.CharField(max_length=10) 

And when I want to get all the comments from a post somepost.comments() I get the following error:

>> somepost.comments() Traceback (most recent call last):   File "<console>", line 1, in <module>   File "a_path/django/db/models/fields/related.py", line 693, in __call__     manager = getattr(self.model, kwargs.pop('manager')) KeyError: 'manager' 
like image 729
andorov Avatar asked Oct 01 '15 13:10

andorov


1 Answers

It should be somepost.comments.all().

somepost.comments returns a queryset. all accesses the objects in it.

like image 107
andorov Avatar answered Sep 18 '22 11:09

andorov