modify or update values django.utils.datastructures.MergeDict

suppose you have a django form

  f = django.forms.Form()
  f.is_valid()
  f.data['field'] = 'new value' # won't work
  f.cleaned_data['key'] = 'value' # won't work

the output of f.as_p() is still the old value because the f.data is a MergeDict.

The way to modify it:

  d = dict(f.data, field='new value')
  f.data = d

MergeDict is for pussies.

newdict = dict(mydict, key='new value') is better than newdict = mydict.copy()

Comments