gault-millau/apps/rating/tasks.py
Виктор Гладких 295bda4b4f Add hours
2019-10-03 11:41:52 +03:00

23 lines
469 B
Python

from datetime import timedelta
from celery import task
from rating.models import Rating
from django.contrib.contenttypes.models import ContentType
def add_rating(remote_addr, pk, model):
add.apply_async(
(remote_addr, pk, model), countdown=60 * 60
)
@task
def add(remote_addr, pk, model):
rating = Rating()
rating.ip = remote_addr
rating.object_id = pk
rating.content_type = ContentType.objects.get(model=model)
rating.save()