Overriding the Update method of Django queryset

10,276

If I have understood your question correctly, you are unable to call the update method in the super class. if so that's because you are calling it wrong. Here is how:

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

In the case of python 3.x the class name and self become optional parameters. So the above line can be shortened to

super().update(*args, **kwargs) 
Share:
10,276
Srinivas M
Author by

Srinivas M

Updated on June 03, 2022

Comments

  • Srinivas M
    Srinivas M almost 2 years

    As part of one of the requirement, we are overriding the Update method in the custom Queryset.

    Sample code is as follows.

    from django.db.models.query import QuerySet
    
    class PollQuerySet(QuerySet):
        def update(self, *args, **kwargs):
            # Some Business Logic
    
            # Call super to continue the flow -- from below line we are unable to invoke super
            super(self, kwargs)
    
    class Question(models.Model):
        objects = PollQuerySet.as_manager()
    
        question_text = models.CharField(max_length=200)
        pub_date = models.DateTimeField('date published')
    

    It is unable to invoke update in base Queryset from the Custom Queryset.

    TypeError at /polls/ must be type, not PollQuerySet

    Any solution is much appreciated.

  • danielcorreia
    danielcorreia about 7 years
    Question tagged with python3 so, super().update(*args, **kwargs). :)