Okay, so I am working on creating some commands in django, but I came across a intriguing issue with regards to my code here...
from django.core.management.base import LabelCommand
from optparse import make_option
class Command(LabelCommand):
requires_system_checks = False
can_import_settings = True
args ="[none]"
label = "person's name"
option_list = LabelCommand.option_list + (
make_option('--cap',
action='store_true',
dest='capitalize',
help= 'Tells Django to capitalize the name'),
)
help = "Runs a shell output that writes out 'Hello' and the specified name"
def handle_label(self, name, **options):
if options.get('capitalize', False):
name = name.capitalize()
print ("Hello %s!" % name)
What bothers me revolves around the handle_label
def in the latter part of the code, and this apparent difference between self and object inputs. I thought that self was the instance inherited from the main class (in this case, Command). Im confused about this, because if I am actually inputting an object (in this case, name) into this method, then why do I need self? I am not referencing it here, why should I need to input this as a parameter? Perhaps Im not understanding this method very well. Either way, can someone help me clarify these differences? Thanks.