You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
That's a good idea! To clarify what you're suggesting:
If update_fields is None, or the computed field name appears, then compute the value and save to the database.
If update_fields is set to some other set of fields not including the computed field, then don't save it to the database.
So, a contrived example to show a possibly confusing side effect of this:
classFoo(models.Model):
value=models.IntegerField()
doubled=ComputedIntegerField(compute_from='compute_val')
@propertydefcompute_val(self):
return2*self.valuemy_foo=Foo.objects.create(value=4)
# (db should have value=4, doubled=8)my_foo.value=5# my_foo.doubled == 10my_foo.save(update_fields=['value'])
# (db has value=5, doubled=8) <--- this is what might be surprising
I can where there might be situations where this is desired. Is this the behavior that you are after?
The situation I encountered is this: for a new computed_field i should implement 'compute_from' function in the migration file for every computed fields implemented before, could not just import these functions couse of migration and code compatability, and thats disgusting. U just showed the other side effect, thank you!
Would be better to consider that)
The text was updated successfully, but these errors were encountered: