MultilingualManager question

29 views
Skip to first unread message

mm...@8ksoft.com.ar

unread,
Apr 29, 2015, 12:07:06 PM4/29/15
to django-mode...@googlegroups.com
I have a doubt about MultilingualManager.
Suppose you have the following models.py and translation.py.
Then when I wont to retrieve only published objects using the custom PublishManager, I get all the objects, not only published==True.

## translation.py
from modeltranslation.translator import translator,TranslationOptions
from foo.models import Bar

class BarTranslationOptions(TranslationOptions):
    fields = ('text',)

translator.register(Bar, BarTranslationOptions)

##models.py
from django.db import models

class PublishManager(models.Manager):
    def get_query_set(self):
        return super(PublishManager, self).get_query_set().filter(publish=True)

class Foo(models.Model):
    text = models.CharField(max_length=100)
    publish = models.BooleanField(default=True)
    objects = models.Manager()
    published = PublishManager()

    class Meta:
        abstract = True

    def __unicode__(self):
        return self.text

class Bar(Foo):
    pass

>>> from foo.models import Bar
>>> Bar.objects.all()
[<Bar: aa>, <Bar: bb>]
>>> Bar.published.all()
[<Bar: aa>, <Bar: bb>]
>>> Bar.published.__class__
<class 'modeltranslation.translator.NewMultilingualManager'>
>>> a=Bar.objects.all()[0]
>>> b=Bar.objects.all()[1]
>>> a.publish
True
>>> b.publish
False
>>>

This is the expected behavior of MultilingualManager patch? I does not understand this behavior... or its some class of bug?

Currently, I'm using Django==1.4.17  and django-modeltranlation==0.9

mm...@8ksoft.com.ar

unread,
Apr 29, 2015, 4:07:45 PM4/29/15
to django-mode...@googlegroups.com

I've posted the issue #307. See https://github.com/deschler/django-modeltranslation/issues/307
A workaround is replace get_query_set for get_queryset.
Reply all
Reply to author
Forward
0 new messages