mirror of
https://github.com/Findus23/acronomy.git
synced 2024-09-19 15:33:45 +02:00
optionally set todays acronyms of the day
This commit is contained in:
parent
47cf64d2cd
commit
708f87a270
1 changed files with 12 additions and 2 deletions
|
@ -8,12 +8,22 @@ from acros.models import Acronym, AcroOfTheDay
|
|||
class Command(BaseCommand):
|
||||
help = 'Selects Acronym of the Day for the next day'
|
||||
|
||||
def add_arguments(self, parser):
|
||||
# Named (optional) arguments
|
||||
parser.add_argument(
|
||||
'--today',
|
||||
action='store_true',
|
||||
help='replace todays acronyms of the day instead of tomorrows',
|
||||
)
|
||||
|
||||
def handle(self, *args, **options):
|
||||
today = date.today()
|
||||
tomorrow = today + timedelta(days=1)
|
||||
AcroOfTheDay.objects.filter(date__gt=today).delete()
|
||||
if options["today"]:
|
||||
AcroOfTheDay.objects.filter(date=today).delete()
|
||||
AcroOfTheDay.objects.filter(date__lt=today).delete()
|
||||
selected = Acronym.objects.order_by('?')[:5]
|
||||
for i,acr in enumerate(selected):
|
||||
AcroOfTheDay.objects.create(acronym=acr, date=tomorrow,order=i)
|
||||
for i, acr in enumerate(selected):
|
||||
AcroOfTheDay.objects.create(acronym=acr, date=today if options["today"] else tomorrow, order=i)
|
||||
print(acr.name)
|
||||
|
|
Loading…
Reference in a new issue