update Tag.book_count in celery
[wolnelektury.git] / apps / catalogue / tasks.py
diff --git a/apps/catalogue/tasks.py b/apps/catalogue/tasks.py
new file mode 100755 (executable)
index 0000000..5566fe1
--- /dev/null
@@ -0,0 +1,16 @@
+# -*- coding: utf-8 -*-
+# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
+# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
+#
+from datetime import datetime
+from celery.task import task
+
+
+@task
+def touch_tag(tag):
+    update_dict = {
+        'book_count': tag.get_count(),
+        'changed_at': datetime.now(),
+    }
+
+    type(tag).objects.filter(pk=tag.pk).update(**update_dict)