Django 1.7, KeyError: u'manager' error

1,407 views
Skip to first unread message

Taenyon Kim

unread,
Oct 17, 2014, 5:23:23 AM10/17/14
to django...@googlegroups.com
Example

class ModelA(models.Model):
    fielda = models.CharField(max_length=10)

class ModelB(models.Model):
    modela = models.ForeignKey(ModelA)
    fieldb = models.CharField(max_length=10)


When I query like "modela_instance.modelb_set()", then I will get KeyError: u'manager' as shown below:


How can I solve this problem?

Sanjay Bhangar

unread,
Oct 17, 2014, 7:10:16 AM10/17/14
to django...@googlegroups.com
On Fri, Oct 17, 2014 at 2:53 PM, Taenyon Kim <xos...@gmail.com> wrote:
Example

class ModelA(models.Model):
    fielda = models.CharField(max_length=10)

class ModelB(models.Model):
    modela = models.ForeignKey(ModelA)
    fieldb = models.CharField(max_length=10)


When I query like "modela_instance.modelb_set()", then I will get KeyError: u'manager' as shown below:

AFAIK, you want something like "modela_instance.modelb_set.all()" - just modela_instance.modelb_set() is the manager instance that you call call methods on (like 'all', 'filter', etc.), but calling the manager directly doesn't quite work, as you found out :)

All the best,
Sanjay

Reply all
Reply to author
Forward
0 new messages