Skip to content

How to invalidate objects in queryset when using bulk update?  #136

Description

@whitefoxx

No signals were send by django update method, right? so, how to invalidate the objects when using

model.objects.filter(**kwargs).update(**kwargs)? 

I wrote this method to invalidate the objects return by filter method explicitly, will it work?

def nocache_update(qset, **kwargs):
    from cacheops import invalidate_obj
    for obj in qset.iterator():
        try:
            invalidate_obj(obj)
        except:
            pass
    # update must behind invalidate obj
    n = qset.update(**kwargs)
    return n

And call this method as follow:

qset = model.objects.filter(**kwargs)
nocache_update(qset, **kwargs)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions