In PHP you can create form elements with names like:
category[1]
category[2]
or even
category[junk]
category[test]
When the form is posted, category is automatically turned into a nice dictionary like:
category[1] => "the input value", category[2] => "the other input value"
Is there a way to do that in Django? request.POST.getlist isn’t quite right, because it simply returns a list, not a dictionary. I need the keys too.
You could use
django.utils.datastructures.DotExpandedDictwith inputs named category.1, category.2 etc. to do something similar, but I don’t really see why you would if you ever have to validate and redisplay the information you’re receiving, when using a django.forms.Form will do everything for you – appropriate fields will call thegetlistmethod for you and theprefixargument can be used to reuse the same form multiple times.