Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Django Parler shows translated object one time per translation on the admin list #330

Open
temperatio opened this issue Jan 18, 2023 · 5 comments

Comments

@temperatio
Copy link

I'm using Django 4.1 and django-parler 2.3

Parler related config in settings.py

LANGUAGES = [
    ('en', _('English')),
    ('es', _('Spanish')),
    ('fr', _('French')),
    ('it', _('Italian')),
    ('de', _('German')),
    ('pt', _('Portuguese')),
    ('nl', _('Dutch')),
    ('pl', _('Polish')),
]

PARLER_LANGUAGES = {
    None: (
        {'code': 'en', },
        {'code': 'es', },
        {'code': 'fr', },
        {'code': 'it', },
        {'code': 'de', },
        {'code': 'pt', },
        {'code': 'nl', },
        {'code': 'pl', },
    ),
    'default': {
        'fallback': 'en',  # defaults to PARLER_DEFAULT_LANGUAGE_CODE
        'hide_untranslated': False,  # the default; let .active_translations() return fallbacks too.
    }
}

I created a model using TranslatableModel and TranslatableAdmin. Then I created an object and filled the translatable fields of the same object for every language. When I get to the model list page, I see oneobjects in the list for every translated lenguage. (As you can see on the screenshot below)

2023-01-18 11_26_50-Select product to change _ Django administration

It's a bug or I'm doing something wrong.

Regards,
César.

@temperatio
Copy link
Author

no one?

@temperatio
Copy link
Author

Is this project abandoned?

@bielfrontera
Copy link

Hi @temperatio,
I've found myself with the same problem!

As a workaround, despite it does not solve the problem but mitigates it a bit, I've added a list filter to show the records translated to the selected language (and they appear only once).

This is the code of the language filter:

from django.conf import settings
from django.contrib import admin
from parler.admin import TranslatableAdmin
from parler.managers import TranslatableQuerySet

class LanguageListFilter(admin.SimpleListFilter):
    title = _("language")
    parameter_name = "language"

    def lookups(self, request, model_admin):
        return settings.LANGUAGES

    def queryset(self, request, queryset):
        if not self.value():
            return queryset
        if not isinstance(queryset, TranslatableQuerySet):
            return queryset
        return queryset.translated(self.value())

class MyModelAdmin(TranslatableAdmin):
    model = MyModel
    list_filter = (LanguageListFilter, )

@bielfrontera
Copy link

@temperatio: are you ordering by a translated field? I've been digging more about this problem, and I've found that I had duplicates if I add order_by("translations__name") (for example) to the queryset.

@temperatio
Copy link
Author

@bielfrontera I have search_fields = ('translations__name')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants