This is the what-I-want ( warning: Python noob here, this might be an incorrect way of representing, but I hope you get what I want )
forms = {
{ 'id' : '1',
'form' : form_something,
},
{ 'id' : '4',
'form' : form_something2,
}
}
Now my question is how do I create this dictionary in my django view which goes like this, so far->
links = Links.objects.all()
forms = {}
for link in links:
form = LinkForm(instance = link )
forms.update({ 'id' : link.id, 'form' : form})
# which is obviously the wrong way to do it
This will create a list of dictionaries:
If you want to create a dictionary of dictionaries, you have to have keys:
Notice I changed where you had spaces in your code to match the standard Python way, but it doesn’t really matter.
The form of the nested dictionary would be:
I added keys and removed the comma from after
form_something2.