1
0
mirror of https://github.com/django/django.git synced 2024-11-19 07:54:07 +00:00
django/tests/regressiontests/defer_regress/models.py
Anssi Kääriäinen b6c356b7bb Fixed #17485 -- Made defer work with select_related
This commit tackles a couple of issues. First, in certain cases there
were some mixups if field.attname or field.name should be deferred.
Field.attname is now always used.

Another issue tackled is a case where field is both deferred by
.only(), and selected by select_related. This case is now an error.

A lot of thanks to koniiiik (Michal Petrucha) for the patch, and
to Andrei Antoukh for review.
2012-06-26 18:08:42 +03:00

54 lines
1.3 KiB
Python

"""
Regression tests for defer() / only() behavior.
"""
from django.db import models
class Item(models.Model):
name = models.CharField(max_length=15)
text = models.TextField(default="xyzzy")
value = models.IntegerField()
other_value = models.IntegerField(default=0)
def __unicode__(self):
return self.name
class RelatedItem(models.Model):
item = models.ForeignKey(Item)
class Child(models.Model):
name = models.CharField(max_length=10)
value = models.IntegerField()
class Leaf(models.Model):
name = models.CharField(max_length=10)
child = models.ForeignKey(Child)
second_child = models.ForeignKey(Child, related_name="other", null=True)
value = models.IntegerField(default=42)
def __unicode__(self):
return self.name
class ResolveThis(models.Model):
num = models.FloatField()
name = models.CharField(max_length=16)
class Proxy(Item):
class Meta:
proxy = True
class SimpleItem(models.Model):
name = models.CharField(max_length=15)
value = models.IntegerField()
def __unicode__(self):
return self.name
class Feature(models.Model):
item = models.ForeignKey(SimpleItem)
class ItemAndSimpleItem(models.Model):
item = models.ForeignKey(Item)
simple = models.ForeignKey(SimpleItem)