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

Admin search_fields and prepopulated_fields #314

Open
urtzai opened this issue Sep 30, 2016 · 8 comments
Open

Admin search_fields and prepopulated_fields #314

urtzai opened this issue Sep 30, 2016 · 8 comments

Comments

@urtzai
Copy link

urtzai commented Sep 30, 2016

I get this error:

hvad.exceptions.WrongManager: To access translated fields like 'name' from an untranslated model, you must use a translation aware manager. For non-translatable models, you can get one using hvad.utils.get_translation_aware_manager.
For translatable models, use the language() method.
@spectras
Copy link
Collaborator

spectras commented Sep 30, 2016

Hello,
Support for using translatable fields in admin is incomplete for several reasons. In short, Django admin app is not built in a way that allows external plugins such as hvad to alter its behaviour - we managed to create workarounds for some use cases, but that's limited in essence.
If you browse hvad's open issues, they are almost all about the admin :(

I guess there is some lobbying to do before serious advances can be made on that.

@urtzai
Copy link
Author

urtzai commented Oct 3, 2016

Hello @spectras,
Ok, I understand... :( So meanwhile, which are those workarounds? Which is the best solution in each case? I need to put at least a basic filter and prepopulated fields....

Thank you very much

@spectras
Copy link
Collaborator

Sorry for the delay, really really low on time. I hope you could find a working solution since, but anyway:

You can have a look at #187 and #303 for further information on this subject and some of the workarounds. Each admin configuration option pretty much requires a different workaround so it's hard to answer without details.

@urtzai
Copy link
Author

urtzai commented Nov 2, 2016

Thank you!! That worked for me!

@urtzai
Copy link
Author

urtzai commented Nov 2, 2016

Sorry @spectras... I tried to config a prepopulated field based on a translatable field but this workaround doesn't work anymore:

#98 (comment)

Is there any other solution?

@realsby
Copy link

realsby commented Jun 19, 2017

+1

@VdeJong
Copy link

VdeJong commented Apr 25, 2018

The workaround doesn't fix this issue anymore. Anyone found a new workaround compatible with hvad==1.8.0 and django 1.11?

@Tyrdall
Copy link

Tyrdall commented Feb 13, 2019

@VdeJong You can add an own admin template admin/change_form.html and add some custom JS :)

{% extends 'admin/change_form.html' %}
{% load staticfiles %}

{% block admin_change_form_document_ready %}
  {{ block.super }}
  <script
      type="text/javascript"
      id="django-admin-prepopulated-fields-constants"
      src="{% static "admin/js/prepopulate_init.js" %}"
      data-prepopulated-fields="[{&quot;name&quot;: &quot;slug&quot;, &quot;dependency_list&quot;: [&quot;title&quot;], &quot;allowUnicode&quot;: false, &quot;maxLength&quot;: 1024, &quot;dependency_ids&quot;: [&quot;#id_title&quot;], &quot;id&quot;: &quot;#id_slug&quot;}]"
  >
  </script>
{% endblock %}

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

5 participants