Quick Django Foreign-key Gotcha

When your Django app poops out with:

'RelatedManager' object is not callable

The problem might be that you’re trying to call up related fields via a foreign key field type’s auto-generated reverse-lookup attribute — but mistakenly trying to call it as a method instead of as an attribute that holds a query set. In code terms, you put:

tracks = cd.track_set()

What you meant to do was:

tracks = cd.track_set.all()

Tags: , , , , ,

One Response to “Quick Django Foreign-key Gotcha”

  1. Aaron says:

    Thank you for posting this blog article. I initially looked on StackOverflow, but couldn’t find the answer, so this helped me fix the error.

    Thanks

Leave a Reply