Answer the question
In order to leave comments, you need to log in
How to implement the command to load tasks into an application from a file?
Call example:
my-venv) $ python manage.py tasks_read_from_file --file input.txt
# coding: utf-8
from django.core.management import BaseCommand
from datetime import datetime
from tasks.models import TodoItem
class Command(BaseCommand):
help = u"Read tasks from file (one line = one task)and save them to db"
def add_arguments(self, parser):
parser.add_argument('--file', dest='input_file', type=str)
def handle(self, *args, **options):
now = datetime.now(timezone.utc)
# ...
Answer the question
In order to leave comments, you need to log in
Well, then pass the argument normally --file=input.txt, and pull another command: management.call_command()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question