pythondjangodjango-templatesmodelformtemplatetags

How to see all possible attributes of an context variables in DjangoTtemplates?


I'm trying to use double model form at once in one single view. I'm using django-betterforms to merge those. It merged all fields from two model in one single form. I know I can use different class and id to separate them but I can't extract them in template form, like:

{{ form }}

It will place full form in template. I can render all field like this:

{% for field in form %}
    {{ field }} or anything
{% endfor %}

My question is how can I know all the possible attributes of this field like:

{{ field.* }} *=anything

kind of dir(field).

I'm facing this problem but what will be solution to find all attributes or separate two forms in two side. Basically, I need to separate two model. Those will save at the same time with same view but in front-end those will be different.

Thanks in advance!!!


Solution

  • You create a custom filter:

    in templatetags/my_filters.py:

    from django import template
    
    register = template.Library()
    
    @register.filter
    def getallattrs(value):
        return dir(value)
    

    in your template:

    {% load my_filters %}
    ...
    {{ field|getallattrs }}