1
Fork 0
yamdl-playground/yamdl_playground/core/apps.py

23 lines
747 B
Python
Raw Normal View History

2023-12-08 14:53:17 +00:00
from django.apps import AppConfig
from django.db import connections
from django.db.models.signals import post_save
class CoreConfig(AppConfig):
name = "yamdl_playground.core"
loaded = False
def ready(self):
if not self.loaded:
connection = connections["default"]
with connection.cursor() as cursor:
cursor.execute("CREATE VIRTUAL TABLE search_index USING fts5(body);")
post_save.connect(self.post_save)
self.loaded = True
def post_save(self, sender, instance, created, **kwargs):
with connections["default"].cursor() as cursor:
cursor.execute("INSERT INTO search_index(body, rowid) VALUES (%s, %s)", [instance.content, instance.pk])