Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Функция получатель
- from .management.commands.db_hour import Command, usr_hour
- from django.dispatch import receiver
- from .models import MySession, Session, Board
- usr_in_hour = []
- @receiver(usr_hour, sender=Command)
- def my_callback(sender, **kwargs):
- usr_in_hour.clear()
- boards = Board.objects.all().values('board_shortcut')
- for x in boards:
- usr_in_hour.append(MySession.objects.filter(name_board__contains=x['board_shortcut']).count())
- Своя команда и функция отправитель
- from django.core.management.base import BaseCommand
- from django.utils import timezone
- import datetime
- from boards.models import MySession, Session
- from django.dispatch import Signal
- usr_hour = Signal(providing_args=[])
- class Command(BaseCommand):
- def handle(self, *args, **options):
- now = timezone.now()
- two_hour = now - datetime.timedelta(hours=2)
- MySession.objects.filter(expire_date__range=(two_hour, now)).delete()
- Session.objects.filter(expire_date__range=(two_hour, now)).delete()
- usr_hour.send(sender=self.__class__)
- self.stdout.write('Succes')
- Вьюха
- from .signals import usr_in_hour
- # Create your views here.
- def index(request):
- boards = Board.objects.all()
- for board in boards:
- board.board_posts = Thread.objects.filter(board=board).count() + Comment.objects.filter(thread__board=board).count()
- return render(request ,'index.html', {'boards': boards, 'usr_in_hour': usr_in_hour})
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement