You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
I noticed an issue in hvad admin (v. 1.8.0)
General usage scenario for me is:
we serve documents in 4 languages
better serving a copy of one language into another than nothing.
I need to show all translations with django rest framework (works perfectly)
(Simplified) model:
from django.db import models
from hvad.models import TranslatableModel, TranslatedFields
class BindingDocument(TranslatableModel):
translations = TranslatedFields(
document=models.FileField(),
label=models.CharField(_("Document label"), max_length=255),
)
admin:
from django.contrib import admin
from django.conf import settings
from hvad.admin import TranslatableAdmin
from .models import BindingDocument
@admin.register(BindingDocument)
class BindingDocumentAdmin(TranslatableAdmin):
list_display = ('all_translations',)
def get_queryset(self, request):
return BindingDocument.objects.prefetch_related('translations')
def save_model(self, request, obj, form, change):
super().save_model(request, obj, form, change)
document = obj.document
label = obj.label
for (language_code, _) in settings.LANGUAGES:
if obj.translations.filter(language_code=language_code).exists():
continue
obj.translate(language_code)
obj.document = document
obj.label = label
obj.save()
Database is filled correctly (i.e. one translation per language is created, all contain same data), rest framework (using TranslationsMixin) also works perfectly.
Admin shows all languages in list view, as expected. However when going to any detail page other than the language in which translation was created, the result is blank. When entering content in blank fields, I get a duplicate key value violates unique constraint "products_bindingdocument_language_code_master_id_add98726_uniqexception.
My guess is that it has something to do with cache internals. Looks like a bug to me, perhaps it has a workaround?
The text was updated successfully, but these errors were encountered:
Hi,
I noticed an issue in hvad admin (v. 1.8.0)
General usage scenario for me is:
(Simplified) model:
admin:
Database is filled correctly (i.e. one translation per language is created, all contain same data), rest framework (using
TranslationsMixin
) also works perfectly.Admin shows all languages in list view, as expected. However when going to any detail page other than the language in which translation was created, the result is blank. When entering content in blank fields, I get a
duplicate key value violates unique constraint "products_bindingdocument_language_code_master_id_add98726_uniq
exception.My guess is that it has something to do with cache internals. Looks like a bug to me, perhaps it has a workaround?
The text was updated successfully, but these errors were encountered: