Hi,

I have a dictionary where the key is the primary key from one of my 
database tables, and the values are the values that I want to update with.

For example, I may have the following dictionary:

new_values = {1:'a', 2:'b', 3:'c'}


And the following model:

class TestThing(models.Model):

    new_value = models.IntegerField(default=0) 


And I want to update the entry with primary key 1 with value 'a', etc.


Note that there are other fields in the table that need to be preserved, so I 
can't just create a new table.


Obviously, I could loop through each entry and update each entry individually, 
but this seems really inefficient, so I think there must be a better way to do 
this.


Also, my table may have entries that aren't represented in my dictionary, so I 
don't think I can do the following:


TestThing.objects.all().update(new_value=new_values[F(id)])


Thanks,

Don

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b8314431-53e7-4c75-bab3-27c8a82840ee%40googlegroups.com.

Reply via email to