trying to show elements of a dictonary that's stored in django model

Viewed 20

What i have is a django project that stores a dictionary in a json model.

class MyModel(models.Model):
    jsonM = JSONField()

The dictionary is just a bunch of numbers. known as my sortedList I am accessing these numbers in my html by passing then as a context variable in my views.py

numbers_in_sortedList = MyModel.objects.all()
return render(
    request,
    "showdata.html",
    context={'numbers_in_sortedList':numbers_in_sortedList },
)

I am able to show the dictionary on my html via:

<li>
{% for number in numbers_in_sortedList %}
    {{item.jsonM}}
{% endfor %}
</li>

this works find and shows 1 bullet point, with all the values in a dictionary. however how can i access each individual element in the dictionary individually? I have tried nesting a for loop but it doesn't seem to work, stating that "myModel object is not iterable"

 <li>  
       {% for number in numbers_in_sortedList %}
        {% for item in number %}
         {{item.jsonM}}
        {% endfor %}
       {% endfor %}
</li>

Any ideas?

0 Answers
Related