I am wondering what is the standard way to update multiple fields of a model instance in django? ... If I have a model with some fields,
Class foomodel(models.Model): field1 = models.CharField(max_length=10) field2 = models.CharField(max_length=10) field3 = models.CharField(max_length=10) ...
... and I create an instance with one field, and then at a separate stage I want to provide the rest of the fields, how can I do this by simply passing in the dictionary parameters or key values? Is it possible?
In other words, let's say I have a dictionary with some data in it that has everything that I want to write to an instance of this model. The model instance was created in a separate step, and let it not be preserved. I can say foo_instance.field1 = my_data_dict['field1'] for each field, but something tells me that there should be a way to call the method in the model instance, where I just pass all the pairs of field values ββat the same time and update them. Something like foo_instance.update(my_data_dict) . I donβt see built-in methods like me, have I missed this or how is it effectively done?
I have the feeling that this is an obvious RTM question, but I just didn't see it in the docs.
django django-models
Purrell Oct. 16 '09 at 7:42 2009-10-16 07:42
source share