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

TranslatableAdmin select only translated models #322

Closed
j-san opened this issue Dec 1, 2016 · 7 comments
Closed

TranslatableAdmin select only translated models #322

j-san opened this issue Dec 1, 2016 · 7 comments

Comments

@j-san
Copy link

j-san commented Dec 1, 2016

Is there any reason for TranslatableAdmin to list only translated models ? Also it looks like (but not tested) that with django < 1.9 there is a different behaviour ?

https://github.com/KristianOellegaard/django-hvad/blob/master/hvad/admin.py#L334

Maybe I've missed somethings, thank you for help 👍

@j-san j-san changed the title TranslatableAdmin does not select untranslated models TranslatableAdmin select only translated models Dec 1, 2016
@spectras
Copy link
Collaborator

spectras commented Dec 1, 2016

Hello!
This is the intended behavior, it was changed in hvad 1.4.0. The exact reasons are deep changes in Django ORM in version 1.9, preventing FallbackQueryset.use_fallbacks() from working at all on this version (and newer).
This forced hvad to push a change that had long been delayed, that is, dropping the inefficient FallbackQueryset in favor of adding a much faster JOIN clause to queries. This has the side-effect of hiding models that have no translation at all.

Such models have always been considered errors anyway (older hvad versions show them, but log an error everytime one is encountered). And hvad2 will prevent them altogether.

I am actually wondering how you create them (admin should not let you create them for instance), and what you use them for?

@spectras spectras added the help label Dec 1, 2016
@j-san
Copy link
Author

j-san commented Dec 2, 2016

In my case (only one model on my db), this model has untranslated representative fields and some optional translatable fields. Instances are created with Django Rest Framework through TranslatableModelSerializer. In most case they are created without translations has long has optional fields are not requested to user.

This instances are no more listed in django admin since Django upgrade. I override get_queryset() on TranslatableAdmin to get all instances.

@spectras
Copy link
Collaborator

spectras commented Dec 2, 2016

Interesting. I guess that's something that should be addressed at the TranslatableModelSerializer level then, it should not create untranslated instances, but always create at least an instance in current or default language, even if its fields are empty.

I see where this happens. When update()-ing models, it always ensures a translation exists, creating it if it is missing. But for initial create()-ion, it relies on the default behavior, assuming there will always be at least one translated field or a language_code.
But, if using the serializer in non-enforce mode, this may be incorrect as the language_code fields is optional.

I will look into it. In the meantime, I suggest you force a language on the serializer, by either of the following means:

  • Pass it a specific language to use when instanciating it. All models will be in that language.
  • Pass it language=None when instanciating it. This will force using detected browser language.
  • Have your javascript always specifiy a language_code field when creating a model.

Overriding get_queryset will work too, but will leave the instances untranslated, which will be a problem in the long run. By the way, if you need help adding default translations back to models that have none right now, just tell.

Thanks for your time :)

@spectras spectras added the bug label Dec 2, 2016
@sonic182
Copy link

There is a way to set language to records added before installing django-havd on my app? I know I just could do a forloop with django shell but something like a task python manage.py havdupdatelanguages would be great to have.

Also It should be said in django-havd admin documentation about old records without language will not be displayed in admin.

@spectras
Copy link
Collaborator

Hello! I'm on holidays accessing github from my phone. This very question was discussed in a recent issue I believe. I can find it when I come back if you want.

@daesu
Copy link

daesu commented Feb 16, 2017

Hello, hope it's not too late to comment on this issue.

I also have hit this issue and I want to make old records visible from before installing hvad. What's the
best way to go about this ?

Thanks

@spectras
Copy link
Collaborator

@daesu> Hello. Please open new issues for new questions :)
I created issue #330 for you. Please see my answer over there.

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

No branches or pull requests

4 participants