1

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

code121
  • 21
  • 4

1 Answers1

0

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.

Joe
  • 462
  • 6
  • 14
  • 1
    The [update](https://docs.djangoproject.com/en/3.0/ref/models/querysets/#update) method of the QuerySet does not emit any signal. – grouchoboy Mar 02 '20 at 16:53
  • UPDATE method does not emit any signal....that's why I want to override it. – code121 Mar 04 '20 at 06:11