This commit is contained in:
Administrator
2022-08-22 15:02:07 +03:00
parent 9e7c4345ed
commit f400b7d0c9
7 changed files with 39 additions and 4 deletions

View File

View File

@@ -0,0 +1,15 @@
from datetime import timedelta
from time import sleep
from django.core.management import BaseCommand
from django.utils import timezone
from battleship.models import Game
class Command(BaseCommand):
def handle(self, *args, **options):
while True:
print('deleting old games')
Game.objects.filter(last_move_ts__lte=timezone.now() - timedelta(days=1)).delete()
sleep(60 * 60 * 24)

View File

@@ -2,6 +2,8 @@ from django.http import JsonResponse
from django.shortcuts import render
# Create your views here.
from django.utils import timezone
from battleship.models import Game, Player, generate_token
@@ -74,6 +76,7 @@ def shoot(request):
else:
new_symb = '.'
player.game.turn = (1 - player.game.turn)
player.game.last_move_ts = timezone.now()
player.game.save()
if pos == 0:
player2.field = new_symb + player2.field[1:]