diff options
| author | Simon Charette <charette.s@gmail.com> | 2014-01-22 01:43:33 -0500 |
|---|---|---|
| committer | Simon Charette <charette.s@gmail.com> | 2014-01-26 14:42:30 -0500 |
| commit | 10e3faf191d8f230dde8534d1c8fad8c8717816e (patch) | |
| tree | 26d597787a0a22f0f11b1d1e0daf0c3b1feb5805 /tests/generic_relations | |
| parent | c3881944e8651ad98e29561154186e87928ca319 (diff) | |
Fixed #19774 -- Deprecated the contenttypes.generic module.
It contained models, forms and admin objects causing undesirable
import side effects. Refs #16368.
Thanks to Ramiro, Carl and Loïc for the review.
Diffstat (limited to 'tests/generic_relations')
| -rw-r--r-- | tests/generic_relations/models.py | 32 | ||||
| -rw-r--r-- | tests/generic_relations/tests.py | 2 |
2 files changed, 18 insertions, 16 deletions
diff --git a/tests/generic_relations/models.py b/tests/generic_relations/models.py index 859a17845e..436f26afb6 100644 --- a/tests/generic_relations/models.py +++ b/tests/generic_relations/models.py @@ -11,7 +11,9 @@ from complete). from __future__ import unicode_literals -from django.contrib.contenttypes import generic +from django.contrib.contenttypes.fields import ( + GenericForeignKey, GenericRelation +) from django.contrib.contenttypes.models import ContentType from django.db import models from django.utils.encoding import python_2_unicode_compatible @@ -24,7 +26,7 @@ class TaggedItem(models.Model): content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() - content_object = generic.GenericForeignKey() + content_object = GenericForeignKey() class Meta: ordering = ["tag", "content_type__name"] @@ -43,7 +45,7 @@ class AbstractComparison(models.Model): content_type1 = models.ForeignKey(ContentType, related_name="comparative1_set") object_id1 = models.PositiveIntegerField() - first_obj = generic.GenericForeignKey(ct_field="content_type1", fk_field="object_id1") + first_obj = GenericForeignKey(ct_field="content_type1", fk_field="object_id1") @python_2_unicode_compatible @@ -55,7 +57,7 @@ class Comparison(AbstractComparison): content_type2 = models.ForeignKey(ContentType, related_name="comparative2_set") object_id2 = models.PositiveIntegerField() - other_obj = generic.GenericForeignKey(ct_field="content_type2", fk_field="object_id2") + other_obj = GenericForeignKey(ct_field="content_type2", fk_field="object_id2") def __str__(self): return "%s is %s than %s" % (self.first_obj, self.comparative, self.other_obj) @@ -66,10 +68,10 @@ class Animal(models.Model): common_name = models.CharField(max_length=150) latin_name = models.CharField(max_length=150) - tags = generic.GenericRelation(TaggedItem) - comparisons = generic.GenericRelation(Comparison, - object_id_field="object_id1", - content_type_field="content_type1") + tags = GenericRelation(TaggedItem) + comparisons = GenericRelation(Comparison, + object_id_field="object_id1", + content_type_field="content_type1") def __str__(self): return self.common_name @@ -80,7 +82,7 @@ class Vegetable(models.Model): name = models.CharField(max_length=150) is_yucky = models.BooleanField(default=True) - tags = generic.GenericRelation(TaggedItem) + tags = GenericRelation(TaggedItem) def __str__(self): return self.name @@ -109,29 +111,29 @@ class Gecko(models.Model): # To test fix for #11263 class Rock(Mineral): - tags = generic.GenericRelation(TaggedItem) + tags = GenericRelation(TaggedItem) class ManualPK(models.Model): id = models.IntegerField(primary_key=True) - tags = generic.GenericRelation(TaggedItem) + tags = GenericRelation(TaggedItem) class ForProxyModelModel(models.Model): content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() - obj = generic.GenericForeignKey(for_concrete_model=False) + obj = GenericForeignKey(for_concrete_model=False) title = models.CharField(max_length=255, null=True) class ForConcreteModelModel(models.Model): content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() - obj = generic.GenericForeignKey() + obj = GenericForeignKey() class ConcreteRelatedModel(models.Model): - bases = generic.GenericRelation(ForProxyModelModel, for_concrete_model=False) + bases = GenericRelation(ForProxyModelModel, for_concrete_model=False) class ProxyRelatedModel(ConcreteRelatedModel): @@ -143,4 +145,4 @@ class ProxyRelatedModel(ConcreteRelatedModel): class AllowsNullGFK(models.Model): content_type = models.ForeignKey(ContentType, null=True) object_id = models.PositiveIntegerField(null=True) - content_object = generic.GenericForeignKey() + content_object = GenericForeignKey() diff --git a/tests/generic_relations/tests.py b/tests/generic_relations/tests.py index 8cd319bf03..ed12c5e92b 100644 --- a/tests/generic_relations/tests.py +++ b/tests/generic_relations/tests.py @@ -1,7 +1,7 @@ from __future__ import unicode_literals from django import forms -from django.contrib.contenttypes.generic import generic_inlineformset_factory +from django.contrib.contenttypes.forms import generic_inlineformset_factory from django.contrib.contenttypes.models import ContentType from django.test import TestCase from django.utils import six |
