farhan0581 / django-admin-autocomplete-filter

A simple Django app to render list filters in django admin using autocomplete widget.
GNU General Public License v3.0
351 stars 76 forks source link

Missing attribute in template: spec.field #20

Closed joke2k closed 4 years ago

joke2k commented 5 years ago

We need that?

https://github.com/farhan0581/django-admin-autocomplete-filter/blob/64c750ffb4be8fc642df5caba639095fab6f2826/admin_auto_filters/templates/django-admin-autocomplete-filter/autocomplete-filter.html#L7

farhan0581 commented 5 years ago

To render the field ?

joke2k commented 5 years ago

Debugging it seems to be always empty. The field is rendered with the row above as a widget.

serl commented 1 month ago

I'm using pytest-django and I want to permanently activate the FAIL_INVALID_TEMPLATE_VARS option. It actually did help me find a couple of minor bugs in my app.

Problem is: it also finds this spec.field, as it cannot limit itself to a specific app/directory. If it's always empty/unused, I think we can just drop the line (#96).

As a workaround, I just locally (__one_of_my_apps__/templates/django-admin-autocomplete-filter/autocomplete-filter.html) re-implemented the template as:

{% load i18n %}
{% if not spec.is_placeholder_title %}
    <h3>{% blocktrans with filter_title=title %} By {{ filter_title }} {% endblocktrans %}</h3>
{% endif %}
    <ul>
        <li>{{ spec.rendered_widget }}</li>
    </ul>

Everything seem to work as expected

merwok commented 1 month ago

Looking at the code, the right attribute may be form_field, or the code need to be changed from field = self.form_field(...) to self.field = self.form_field(...)

merwok commented 1 month ago

No, tested both and they don’t render anything useful. The first li element contains what is necessary to have the autocomplete filter working.