Reputation: 1406
I have a class like this in django app views.py
from dms.models import Folder, File, FileTag
class GetFamily:
def getFathers(folder_id):
if folder_id == None:
rev_fathers=None
else:
fathers=[]
rev_fathers=[]
father=Folder.objects.get(id=folder_id)
fathers.append(father)
while father.parent_folder_id != None:
father=Folder.objects.get(id=father.parent_folder_id)
fathers.append(father)
rev_fathers=reversed(fathers)
return rev_fathers
def getChildrenFolders(folder_id):
folders=Folder.objects.filter(parent_folder_id=folder_id)
return folders
def getChildrenFiles(folder_id):
files=File.objects.filter(folder_id=folder_id)
return files
When i call getFathers(folder_id) method with id it gives getFathers() takes exactly 1 argument (2 given)
Plese help me out
Upvotes: 1
Views: 435
Reputation: 227468
getFathers
is a method of class GetFamily
, so it needs a first parameter for the instance. The convention in python is to use the name self
for this parameter:
def getFathers(self, folder_id):
Note that the function itself does not access any of the class' members. This is often a good indicator that it does not need to be a method of the class, or that it would be declared as a static method using @staticmethod
.
Upvotes: 5
Reputation: 4673
Either include self
in the arguments:
def getFathers(self, folder_id):
Or, if it won't need any instance variables, mark it as a staticmethod
:
@staticmethod
def getFathers(folder_id):
Upvotes: 1