Say I have a model like
class MyModel(models.Model)
name = models.CharField(max_length=100)
number = models.IntegerField()
In a script, I want to have something like
fields = {"name":"Joe", "number":5}
And I want to update a MyModel instance using the fields dictionary, something like this
inst = MyModel.objects.get(pk=2)
for k,v in fields.iteritems():
inst.k = v # I tried with inst.F(k) = v and inst.eval(k) = v but python doesn't like that either
I hope I'm being clear in what I'm trying to do. The reason I have to do it this way is that I don't know which model, and therefore fields, I'm dealing with until run-time.
Please ask questions if this isn't clear.