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

Include unpopulated fields in the serialized data? #3

Open
anyong opened this issue Apr 17, 2015 · 1 comment
Open

Include unpopulated fields in the serialized data? #3

anyong opened this issue Apr 17, 2015 · 1 comment

Comments

@anyong
Copy link

anyong commented Apr 17, 2015

How difficult would this be to implement?

In the main parler package there is a hide_untranslated option for settings that can be turned off to allow untranslated fields to show in the admin. I'd like to be able to show all of the untranslated fields in an admin form that works via REST API, so I'd like to be able to incorporate this setting into the serializer.

If you have any tips please let me know but I'm working on it now and I'll submit a PR if I come up with anything...

Currently have something like this in fields.py just before return result:

Fork

if settings.PARLER_REST_SHOW_EXCLUDED_LANGUAGE_TABS:
    existing_languages = [lg_code for lg_code in result]
    settings_languages = [language[0] for language in settings.LANGUAGES]
    empty_languages = [lg_code for lg_code in settings_languages if lg_code not in existing_languages]
    for lg_code in empty_languages:
        result[lg_code] = None

This is not a great option though since there are no fields included in the resulting serialized data. Ideally there would be blank fields ready to fill in, the same way as they would appear in the django admin.

@vdboor
Copy link
Contributor

vdboor commented Apr 19, 2015

I think the best way to represent those empty translations, is by offering them as an empty dict {}.

Note that hide_untranslated and PARLER_REST_SHOW_EXCLUDED_LANGUAGE_TABS are two separate things.

  • The hide untranslated makes any object disappear in the listing if there is no translation. Some of my sites use that to hide untranslated pages (instead of showing them as english).
  • The PARLER_REST_SHOW_EXCLUDED_LANGUAGE_TABS tests if there are languages in the database which are not exposed in LANGUAGES / PARLER_LANGUAGES.

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