summaryrefslogtreecommitdiff
path: root/tests/generic_relations
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2013-10-03 13:44:10 -0400
committerSimon Charette <charette.s@gmail.com>2013-10-04 16:23:06 -0400
commit948d209adac566d89f44f073fdd77a371c18e269 (patch)
tree6dece7d834a68dc1f532a3b06483b38988c2aab5 /tests/generic_relations
parentdc3d2ac98c1bcfad74d3e9523caf07e7e9fb15aa (diff)
downloaddjango-948d209adac566d89f44f073fdd77a371c18e269.tar.gz
Fixed #21217 -- Avoid connecting `(pre|post)_init` signals to abstract senders.
Diffstat (limited to 'tests/generic_relations')
-rw-r--r--tests/generic_relations/models.py30
1 files changed, 23 insertions, 7 deletions
diff --git a/tests/generic_relations/models.py b/tests/generic_relations/models.py
index d819a53c0e..79eb59fe47 100644
--- a/tests/generic_relations/models.py
+++ b/tests/generic_relations/models.py
@@ -32,28 +32,35 @@ class TaggedItem(models.Model):
def __str__(self):
return self.tag
+
class ValuableTaggedItem(TaggedItem):
value = models.PositiveIntegerField()
-@python_2_unicode_compatible
-class Comparison(models.Model):
- """
- A model that tests having multiple GenericForeignKeys
- """
+
+class AbstractComparison(models.Model):
comparative = models.CharField(max_length=50)
content_type1 = models.ForeignKey(ContentType, related_name="comparative1_set")
object_id1 = models.PositiveIntegerField()
- content_type2 = models.ForeignKey(ContentType, related_name="comparative2_set")
+ first_obj = generic.GenericForeignKey(ct_field="content_type1", fk_field="object_id1")
+
+
+@python_2_unicode_compatible
+class Comparison(AbstractComparison):
+ """
+ A model that tests having multiple GenericForeignKeys. One is defined
+ through an inherited abstract model and one defined directly on this class.
+ """
+ content_type2 = models.ForeignKey(ContentType, related_name="comparative2_set")
object_id2 = models.PositiveIntegerField()
- first_obj = generic.GenericForeignKey(ct_field="content_type1", fk_field="object_id1")
other_obj = generic.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)
+
@python_2_unicode_compatible
class Animal(models.Model):
common_name = models.CharField(max_length=150)
@@ -67,6 +74,7 @@ class Animal(models.Model):
def __str__(self):
return self.common_name
+
@python_2_unicode_compatible
class Vegetable(models.Model):
name = models.CharField(max_length=150)
@@ -77,6 +85,7 @@ class Vegetable(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Mineral(models.Model):
name = models.CharField(max_length=150)
@@ -87,18 +96,22 @@ class Mineral(models.Model):
def __str__(self):
return self.name
+
class GeckoManager(models.Manager):
def get_queryset(self):
return super(GeckoManager, self).get_queryset().filter(has_tail=True)
+
class Gecko(models.Model):
has_tail = models.BooleanField(default=False)
objects = GeckoManager()
+
# To test fix for #11263
class Rock(Mineral):
tags = generic.GenericRelation(TaggedItem)
+
class ManualPK(models.Model):
id = models.IntegerField(primary_key=True)
tags = generic.GenericRelation(TaggedItem)
@@ -110,14 +123,17 @@ class ForProxyModelModel(models.Model):
obj = generic.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()
+
class ConcreteRelatedModel(models.Model):
bases = generic.GenericRelation(ForProxyModelModel, for_concrete_model=False)
+
class ProxyRelatedModel(ConcreteRelatedModel):
class Meta:
proxy = True