As I was required to implement a custom management command in my project, I tried to create a dummy command as part of learning. When I executed the custom management command I created, I got the result twice…
My folder structure looks like this
training/
__init__.py
management/
__init__.py
commands/
__init__.py
custom_management.py
Here’s the custom management command I’ve created
from django.core.management.base import BaseCommand
class Command(BaseCommand):
"""
Creates a custom command for updating the previous assessment records
"""
help = "Updates the assessments recordes in a SubBatch"
def add_arguments(self, parser):
"""
This function is responsible for adding arguments to the command
"""
parser.add_argument("--list_a", nargs="*", type=int)
parser.add_argument("--int_x", type=int, default=0)
def handle(self, *args, **kwargs):
"""
Create records based on the given scenario
"""
x = sum(kwargs["list_a"])
y = kwargs["int_x"]
add = x + y
return self.stdout.write(
self.style.SUCCESS('Sum of the values "%i"' % add)
)
When I tried to execute the command, this is the result I got
Can someone explain to me why the result is returned twice?
Also when I try to run my testcases, it gets executed twice…
Thanks in advance