Created
November 25, 2014 11:02
-
-
Save no13bus/b1843b069ca3145ef17c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class models_a(models.Model): | |
value_a = models.FloatField(default=0.0) | |
value_a_1 = models.FloatField(default=0.0) | |
class models_b(models.Model): | |
foreign = models.ForeignKey(models_a) | |
value_b = models.FloatField(default=0.0) | |
####进行更新model_b里面的字段value_b,让他的值等于models_a里面的value_a和value_a_1和value_b这三个值之和 | |
results = models_b.objects.exclude(value_b=0.0) | |
for i in results.iterator(): | |
i.value_b = i.value_b + i.foreign.value_a + i.foreign.value_a_1 | |
i.save() | |
### |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment