code121
code121

Reputation: 21

Override Django queryset update method

I want to override Django Queryset Update method , to log the model changes in another table.I have override the method , but not able to find the id's of the rows which are going to get update.I am getting the fields which are getting changed from kwargs I'm using Django v1.9.5. I went through the docs of django-simple-history and django-reversion , but they don't log changes on update method.

class PollQuerySet(QuerySet):
    def update(self, *args, **kwargs):
        # save data into other table whose schema is 
        #(model_name,field_name,model_pk_id,old_value,new_value)

        super().update(*args, **kwargs)

class ModelWithCustomManager(models.Model):
    objects = PollQuerySet.as_manager()

    class Meta:
        abstract = True

Upvotes: 1

Views: 279

Answers (1)

Joe
Joe

Reputation: 492

Instead of overriding the update method, your may want to look in to signals. On pre-save and post-save you can grab data from the model and save it into a log table.

Upvotes: 0

Related Questions