mirror of
https://github.com/django/django.git
synced 2025-09-16 15:35:17 +00:00
Fixed #26153 -- Reallowed Q-objects in ForeignObject.get_extra_descriptor_filter().
This commit is contained in:
parent
1d86d4c72b
commit
353aecbf8c
5 changed files with 39 additions and 3 deletions
|
@ -44,6 +44,11 @@ class ActiveTranslationField(models.ForeignObject):
|
|||
setattr(cls, self.name, ArticleTranslationDescriptor(self))
|
||||
|
||||
|
||||
class ActiveTranslationFieldWithQ(ActiveTranslationField):
|
||||
def get_extra_descriptor_filter(self, instance):
|
||||
return models.Q(lang=get_language())
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class Article(models.Model):
|
||||
active_translation = ActiveTranslationField(
|
||||
|
@ -54,6 +59,14 @@ class Article(models.Model):
|
|||
on_delete=models.CASCADE,
|
||||
null=True,
|
||||
)
|
||||
active_translation_q = ActiveTranslationFieldWithQ(
|
||||
'ArticleTranslation',
|
||||
from_fields=['id'],
|
||||
to_fields=['article'],
|
||||
related_name='+',
|
||||
on_delete=models.CASCADE,
|
||||
null=True,
|
||||
)
|
||||
pub_date = models.DateField()
|
||||
|
||||
def __str__(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue