carltongibson / neapolitan

Quick CRUD views for Django
https://noumenal.es/neapolitan/
MIT License
413 stars 30 forks source link

Add field name to the list of fields generated by `object_list` templatetag #40

Open joshuadavidthomas opened 5 months ago

joshuadavidthomas commented 5 months ago

Currently the fields rendered out in the list view only contain the values. If I want to customize the rendering of a field based on the field name in an overridden neapolitan list template, there's no good way to do this without writing my own object_list templatetag.

For example, I have a status field that I want to render as a pretty badge because I like the way it looks, this isn't really possible since all I would be able to see is the field's value in the template (so "active", "inactive", etc.) and not the field's name.

image

See this relevant commit for how this would look.

With the above commit, I can then just use something like this in my overridden template:

{% for field in object.fields %}
    {% if field.name == "status" %}
        <td class="py-4 px-3 align-top whitespace-nowrap">{% asset_status_badge field.value %}</td>
    {# etc... #}
    {% endif %}
{% endfor %}
carltongibson commented 5 months ago

Wondering if just returning a dict isn't the way to go then. 🤔