gault-millau/apps/rating/tasks.py
Виктор Гладких 14cf7d7b1b Add rating value in news
2019-10-03 14:46:34 +03:00

23 lines
523 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, app_label):
add.apply_async(
(remote_addr, pk, model, app_label), countdown=60 * 60
)
@task
def add(remote_addr, pk, model, app_label):
rating = Rating()
rating.ip = remote_addr
rating.object_id = pk
rating.content_type = ContentType.objects.get(app_label=app_label, model=model)
rating.save()