Commit 903093c5 by Alex Gaynor

Resolved merge conflicts

parents 0ec48c52 ae115b53
......@@ -106,7 +106,7 @@ class TaggableManager(object):
def m2m_reverse_name(self):
if self.use_gfk:
return "id"
return self.through._meta.get_field('content_object').rel.to._meta.pk.column
return self.through._meta.pk.column
def m2m_column_name(self):
if self.use_gfk:
......
from taggit.tests.tests import (TaggableManagerTestCase, TaggableManagerDirectTestCase,
TaggableFormTestCase, TaggableFormDirectTestCase)
from taggit.tests.tests import (TaggableManagerTestCase, TaggableFormTestCase,
TaggableManagerDirectTestCase,
TaggableFormDirectTestCase,
TaggableManagerCustomPKTestCase,
TaggableFormCustomPKTestCase)
from django import forms
from taggit.tests.models import Food, DirectFood
from taggit.tests.models import Food, DirectFood, CustomPKFood
class FoodForm(forms.ModelForm):
......@@ -10,3 +10,7 @@ class FoodForm(forms.ModelForm):
class DirectFoodForm(forms.ModelForm):
class Meta:
model = DirectFood
class CustomPKFoodForm(forms.ModelForm):
class Meta:
model = CustomPKFood
......@@ -19,6 +19,8 @@ class Pet(models.Model):
class HousePet(Pet):
trained = models.BooleanField()
# test direct-tagging with custom through model
class TaggedFood(TaggedItemBase):
content_object = models.ForeignKey('DirectFood')
......@@ -37,3 +39,24 @@ class DirectPet(models.Model):
class DirectHousePet(DirectPet):
trained = models.BooleanField()
# test custom through model to model with custom PK
class TaggedCustomPKFood(TaggedItemBase):
content_object = models.ForeignKey('CustomPKFood')
class CustomPKFood(models.Model):
name = models.CharField(max_length=50, primary_key=True)
tags = TaggableManager(through=TaggedCustomPKFood)
class TaggedCustomPKPet(TaggedItemBase):
content_object = models.ForeignKey('CustomPKPet')
class CustomPKPet(models.Model):
name = models.CharField(max_length=50, primary_key=True)
tags = TaggableManager(through=TaggedCustomPKPet)
class CustomPKHousePet(CustomPKPet):
trained = models.BooleanField()
from django.test import TestCase
from taggit.models import Tag, TaggedItem
from taggit.tests.forms import FoodForm, DirectFoodForm
from taggit.tests.models import Food, Pet, HousePet, DirectFood, DirectPet, DirectHousePet, TaggedPet
from taggit.tests.forms import FoodForm, DirectFoodForm, CustomPKFoodForm
from taggit.tests.models import (Food, Pet, HousePet,
DirectFood, DirectPet, DirectHousePet,
TaggedPet,
CustomPKFood, CustomPKPet, CustomPKHousePet,
TaggedCustomPKPet)
class BaseTaggingTest(TestCase):
......@@ -54,6 +58,7 @@ class TaggableManagerTestCase(BaseTaggingTest):
apple.delete()
self.assert_tags_equal(self.food_model.tags.all(), ["green"])
def test_require_pk(self):
food_instance = self.food_model()
self.assertRaises(ValueError, lambda: food_instance.tags.all())
......@@ -72,7 +77,7 @@ class TaggableManagerTestCase(BaseTaggingTest):
def test_delete_bulk(self):
apple = self.food_model.objects.create(name="apple")
kitty = self.pet_model.objects.create(id=apple.pk, name="kitty")
kitty = self.pet_model.objects.create(pk=apple.pk, name="kitty")
apple.tags.add("red", "delicious", "fruit")
kitty.tags.add("feline")
......@@ -154,6 +159,16 @@ class TaggableManagerDirectTestCase(TaggableManagerTestCase):
housepet_model = DirectHousePet
taggeditem_model = TaggedPet
class TaggableManagerCustomPKTestCase(TaggableManagerTestCase):
food_model = CustomPKFood
pet_model = CustomPKPet
housepet_model = CustomPKHousePet
taggeditem_model = TaggedCustomPKPet
def test_require_pk(self):
# XXX with a charfield pk, pk is never None, so taggit has no
# way to tell if the instance is saved or not
pass
class TaggableFormTestCase(BaseTaggingTest):
form_class = FoodForm
......@@ -184,3 +199,7 @@ class TaggableFormTestCase(BaseTaggingTest):
class TaggableFormDirectTestCase(TaggableFormTestCase):
form_class = DirectFoodForm
food_model = DirectFood
class TaggableFormCustomPKTestCase(TaggableFormTestCase):
form_class = CustomPKFoodForm
food_model = CustomPKFood
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment