128👍
✅
The error seems clear: model objects do not support item assignment.
MyModel.objects.latest('id')['foo'] = 'bar'
will throw this same error.
It’s a little confusing that your model instance is called projectForm
…
To reproduce your first block of code in a loop, you need to use setattr
for k,v in session_results.iteritems():
setattr(projectForm, k, v)
33👍
Another way would be adding __getitem__, __setitem__ function
def __getitem__(self, key):
return getattr(self, key)
You can use self[key] to access now.
- [Django]-Django edit user profile
- [Django]-Separating form input and model validation in Django?
- [Django]-Inline in ModelForm
Source:stackexchange.com