I have an inline formset for a model, which has a unique_together constraint. And so, when I input data, which doesn’t fulfill this constraint, it displays:
__all__Please correct the duplicate values below.
The code, which does this is:
{% for error in formset.errors %}
{{ error }}<br/>
{% endfor %}
I don’t much like the __all__ at the beginning of the error and it is quite clearly the dictionary key, so I tried:
{% for key, error in formset.errors %}
{{ key }}: {{ error }}<br/>
{% endfor %}
But then all I get is:
__all__:
{{ error }} won’t display at all. So what’s going on here? And how do I display the error correctly?
I think the problem here is that
formset.errorsis a list of dictionaries, not a single dictionary.From the Django docs page on formsets:
See if something like this fixes the problem: (Updated based on the askers comments)
If that fails, I’d try using
manage.py shell, and try to reproduce your situation in the python shell… that way it will be easy to inspect the various values and figure out what you need to do.