我想在模型属性上使用@cached_property 以避免过多的数据库访问。
class AttrGroup(models.Model):
...
@cached_property
def options(self):
options = AttributeOption.objects.filter(group_id=self.id)
return options
...
这很好用。
我想使用下面的函数来更新选项的值。但是我应该怎么做呢?对于属性装饰器,它有 setter 。
def _set_options(self, value):
for option in value:
AttributeOption.objects.create(group_id=self.id, option=option.get('option'))
最佳答案
关于python - 如何更新 django cached_property,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43039188/