rlucas.net: The Next Generation Rotating Header Image

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()

One Comment

  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

Your email address will not be published. Required fields are marked *