Allows custom Through Model with GenericForeignKey #359

Merged
merged 1 commit into from Nov 25, 2015

Projects

None yet

2 participants

@PierreF
Contributor
PierreF commented Nov 20, 2015

This pull request makes possible to use Django-taggit on any models with non-integer primary-key without the need to define one Through Model per tagged model (e.g. using GenericForeignKey not direct ForeignKey).

I moved the common code from GenericTaggedItemBase to a new CommonGenericTaggedItemBase class.

User may then inherit from CommonGenericTaggedItemBase to define a Through Model for custom PK while still using GenericForeignKey.

I've updated the doc to include example of a non-integer primary key and added test.

I've also included a GenericUUIDTaggedItemBase which is the same as GenericTaggedItemBase but for UUID primary-key (since it's probably the most common use case). But since it rely on Django 1.8, it's only defined for Django 1.8+

@frewsxcv
Collaborator

Is it possible to make this backwards compatible? Right now it looks like we're renaming GenericTaggedItemBase to CommonGenericTaggedItemBase which could cause issues for people using it. Not a big deal if we have to do a new release with that breaking change, but if it's avoidable, that'd be ideal

@PierreF
Contributor
PierreF commented Nov 25, 2015

GenericTaggedItemBase still exists. I just moved most of the field & code to CommonGenericTaggedItemBase and GenericTaggedItemBase. So using GenericTaggedItemBase works as it always did.

This is tested, since TaggedItem still use GenericTaggedItemBase and test suite pass.

@PierreF
Contributor
PierreF commented Nov 25, 2015

Oh, and the previous GenericTaggedItemBase was already for tagged models that use an integer primary key. I just made that more clear in the doc.

@frewsxcv
Collaborator

Ah, that makes sense. Thanks for you contribution!

@frewsxcv frewsxcv merged commit 1f8c3de into alex:develop Nov 25, 2015

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
@frewsxcv
Collaborator

Just released version 0.17.4 that includes this change. Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment