alex/django-taggit — pull request #266 by richardxia (2014-09-19 11:29:25+00:00)
Title: Fix joins on taggable managers defined on submodels of multi-table inheritance.

In Django >= 1.6, taggable managers which are only defined on the submodel in a multi-table inheritance relationship incorrectly attempt to join on `id` instead of the submodel's primary key, which is its foreign key to the parent model. This is probably best explained by reading the test that I wrote in this branch, but to reproduce the bug, I essentially copied the Pet and HousePet relationship defined for the other tests and defined the TaggableManager only on HousePet. You can confirm that my test fails on Django 1.6 without the fix contained in this branch.

The reason this fails is that the `get_joining_columns()` method on TaggableManager hardcodes `id` and `object_id` for the generic foreign key to and from fields. This method is only used in Django 1.6 and 1.7, so Django 1.5 and 1.4 aren't affected. To fix this, I copied the definition of [`get_joining_columns()` from Django 1.6.7's ForeignObject](https://github.com/django/django/blob/1.6.7/django/db/models/fields/related.py#L1019-L1021), which is what TaggableManager seems to be modeled after, which dynamically determines which columns to use based on the related fields.

I tested this fix by running the tests, including my new tests, on Django 1.4.8, 1.5.4, 1.6.7, and 1.7.