# Path: ratings/models.py
# class RatedItem(RatedItemBase):
#     object_id = models.IntegerField()
#     content_type = models.ForeignKey(
#         ContentType,
#         related_name="rated_items",
#         on_delete=models.CASCADE,
#     )
#     content_object = GenericForeignKey()
# 
#     @classmethod
#     def lookup_kwargs(cls, instance):
#         return {"object_id": instance.pk, "content_type": ContentType.objects.get_for_model(instance)}
# 
#     @classmethod
#     def base_kwargs(cls, model_class):
#         return {"content_type": ContentType.objects.get_for_model(model_class)}


from django.db.models import signals
from ratings.models import RatedItem



def update_rating_score(sender, instance, *args, **kwargs):
    if instance.content_object and hasattr(instance.content_object, "update_rating"):
        instance.content_object.update_rating()


def start_listening():
    signals.post_save.connect(
        update_rating_score,
        sender=RatedItem,
        dispatch_uid="cab.snippets.save_rating_score",
    )
    signals.post_delete.connect(
        update_rating_score,

# Path: ratings/models.py
# class RatedItem(RatedItemBase):
#     object_id = models.IntegerField()
#     content_type = models.ForeignKey(
#         ContentType,
#         related_name="rated_items",
#         on_delete=models.CASCADE,
#     )
#     content_object = GenericForeignKey()
# 
#     @classmethod
#     def lookup_kwargs(cls, instance):
#         return {"object_id": instance.pk, "content_type": ContentType.objects.get_for_model(instance)}
# 
#     @classmethod
#     def base_kwargs(cls, model_class):
#         return {"content_type": ContentType.objects.get_for_model(model_class)}


# Path: cab/listeners.py
from django.db.models import signals
from ratings.models import RatedItem




def update_rating_score(sender, instance, *args, **kwargs):
    if instance.content_object and hasattr(instance.content_object, "update_rating"):
        instance.content_object.update_rating()


def start_listening():
    signals.post_save.connect(
        update_rating_score,
        sender=RatedItem,
        dispatch_uid="cab.snippets.save_rating_score",
    )
    signals.post_delete.connect(
        update_rating_score,

        sender=RatedItem,