[Python] how to update django cached_property

Discussão em 'Python' iniciado por Stack, Março 14, 2025.

  1. Stack

    Stack Membro Participativo

    I would like to use @cached_property on model property to avoid too much db access.

    class AttrGroup(models.Model):
    ...

    @cached_property
    def options(self):
    options = AttributeOption.objects.filter(group_id=self.id)
    return options
    ...


    This works fine.

    i want to use the following function to update the value of options.But how should i do it? for property decorator, there is setter for it.

    def _set_options(self, value):
    for option in value:
    AttributeOption.objects.create(group_id=self.id, option=option.get('option'))

    Continue reading...

Compartilhe esta Página