1
0
mirror of https://github.com/django/django.git synced 2025-10-29 08:36:09 +00:00

[1.6.x] Fixed #22514 -- Prevented indexes on virtual fields [postgres].

Backport of 78c32f1caa from master
This commit is contained in:
Vlastimil Zíma
2014-05-19 18:19:35 +02:00
committed by Tim Graham
parent d4a3fd44f0
commit ef3ae3d1c9
4 changed files with 38 additions and 3 deletions

View File

@@ -2,10 +2,35 @@ from django.db import connection
from django.db import models
class CurrentTranslation(models.ForeignObject):
"""
Creates virtual relation to the translation with model cache enabled.
"""
# Avoid validation
requires_unique_target = False
def __init__(self, to, from_fields, to_fields, **kwargs):
# Disable reverse relation
kwargs['related_name'] = '+'
# Set unique to enable model cache.
kwargs['unique'] = True
super(CurrentTranslation, self).__init__(to, from_fields, to_fields, **kwargs)
class ArticleTranslation(models.Model):
article = models.ForeignKey('indexes.Article')
language = models.CharField(max_length=10, unique=True)
content = models.TextField()
class Article(models.Model):
headline = models.CharField(max_length=100)
pub_date = models.DateTimeField()
# Add virtual relation to the ArticleTranslation model.
translation = CurrentTranslation(ArticleTranslation, ['id'], ['article'])
class Meta:
index_together = [
["headline", "pub_date"],