1

As I know, *args is a tuple, and **kwargs is a dictionary and the super.save() is used to override the built-in save method and to ensure that the save() is called

but I can't understand why we use in here as parameters **

def save(self,*args,**kwargs):
  super.save(*args,**kwargs)
Amin Mir
  • 640
  • 8
  • 15

1 Answers1

4

TL;DR: You pass *args and **kwargs because your super.save() method accepts these arguments and it has to be passed to the reference for it to properly get executed without errors.

Long Explanation: Think your super() is a gateway to the inherited class, you can call the methods of the parent class via super(). When you say that you want to override something in the parent method you necessarily only want to add to what the existing method is providing.

Like this:

def save(self,*args,**kwargs):
  self.request.user = get_current_logged_in_user() <--- Some validation or cleaning you want to do here.
  super.save(*args,**kwargs)

If you want to completely discourage all the implementation of that save() method from the parent class you just remove the super.save(*args,**kwargs) inside your def save(), but now you will have to implement your custom solution on how the save() method should be handled Which can be opening a database connection, validating the data coming in, firing a query to save the data inside the database, committing the change to the database, and finally closing the database connection.

def save(self):
   # Open a db connection with url, user, password of your db
   # Validate the incoming data
   # Query the db
   # Commit the query
   # Close db connection
Amin Mir
  • 640
  • 8
  • 15
Ruchit Micro
  • 554
  • 3
  • 14