mirror of
https://github.com/django/django.git
synced 2024-12-25 18:46:22 +00:00
0c7633178f
Refactored compiler SELECT, GROUP BY and ORDER BY generation. While there, also refactored select_related() implementation (get_cached_row() and get_klass_info() are now gone!). Made get_db_converters() method work on expressions instead of internal_type. This allows the backend converters to target specific expressions if need be. Added query.context, this can be used to set per-query state. Also changed the signature of database converters. They now accept context as an argument.
107 lines
2.5 KiB
Python
107 lines
2.5 KiB
Python
"""
|
|
Regression tests for defer() / only() behavior.
|
|
"""
|
|
|
|
from django.db import models
|
|
from django.utils.encoding import python_2_unicode_compatible
|
|
|
|
|
|
@python_2_unicode_compatible
|
|
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 __str__(self):
|
|
return self.name
|
|
|
|
|
|
class RelatedItem(models.Model):
|
|
item = models.ForeignKey(Item)
|
|
|
|
|
|
class ProxyRelated(RelatedItem):
|
|
class Meta:
|
|
proxy = True
|
|
|
|
|
|
class Child(models.Model):
|
|
name = models.CharField(max_length=10)
|
|
value = models.IntegerField()
|
|
|
|
|
|
@python_2_unicode_compatible
|
|
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 __str__(self):
|
|
return self.name
|
|
|
|
|
|
class ResolveThis(models.Model):
|
|
num = models.FloatField()
|
|
name = models.CharField(max_length=16)
|
|
|
|
|
|
class Proxy(Item):
|
|
class Meta:
|
|
proxy = True
|
|
|
|
|
|
@python_2_unicode_compatible
|
|
class SimpleItem(models.Model):
|
|
name = models.CharField(max_length=15)
|
|
value = models.IntegerField()
|
|
|
|
def __str__(self):
|
|
return self.name
|
|
|
|
|
|
class Feature(models.Model):
|
|
item = models.ForeignKey(SimpleItem)
|
|
|
|
|
|
class SpecialFeature(models.Model):
|
|
feature = models.ForeignKey(Feature)
|
|
|
|
|
|
class OneToOneItem(models.Model):
|
|
item = models.OneToOneField(Item, related_name="one_to_one_item")
|
|
name = models.CharField(max_length=15)
|
|
|
|
|
|
class ItemAndSimpleItem(models.Model):
|
|
item = models.ForeignKey(Item)
|
|
simple = models.ForeignKey(SimpleItem)
|
|
|
|
|
|
class Profile(models.Model):
|
|
profile1 = models.CharField(max_length=1000, default='profile1')
|
|
|
|
|
|
class Location(models.Model):
|
|
location1 = models.CharField(max_length=1000, default='location1')
|
|
|
|
|
|
class Request(models.Model):
|
|
profile = models.ForeignKey(Profile, null=True, blank=True)
|
|
location = models.ForeignKey(Location)
|
|
items = models.ManyToManyField(Item)
|
|
|
|
request1 = models.CharField(default='request1', max_length=1000)
|
|
request2 = models.CharField(default='request2', max_length=1000)
|
|
request3 = models.CharField(default='request3', max_length=1000)
|
|
request4 = models.CharField(default='request4', max_length=1000)
|
|
|
|
|
|
class Base(models.Model):
|
|
text = models.TextField()
|
|
|
|
|
|
class Derived(Base):
|
|
other_text = models.TextField()
|