R
R
Radiss2020-05-07 14:21:15
Django
Radiss, 2020-05-07 14:21:15

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


Sample:

# 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

1 answer(s)
N
noremorse_ru, 2020-05-07
@noremorse_ru

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 question

Ask a Question

731 491 924 answers to any question