Answer the question
In order to leave comments, you need to log in
How to write an implementation of the handle method for a command that displays tasks that were completed in the last days of days?
An example of calling such a command:
(my-venv) $ python manage.py tasks_report_completed --days 5
# coding: utf-8
from django.core.management import BaseCommand
from datetime import datetime
from tasks.models import TodoItem
class Command(BaseCommand):
help = u"Displays all tasks completed in the last `days` days (default=3
days)"
def add_arguments(self, parser):
parser.add_argument('--days', dest='days', type=int, default=3)
def handle(self, *args, **options):
now = datetime.now(timezone.utc)
# ...
def handle(self, *args, **options):
now = datetime.now(timezone.utc)
for t in TodoItem.objects.filter(is_completed=False):
if (now - t.created).days >= options['--_days']:
print("Задача:", t, t.created)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question