Refactor comments app to use mixins for comment functionality; update admin interfaces and add historical model fixes

This commit is contained in:
pacnpal
2025-02-08 16:33:55 -05:00
parent f000c492e8
commit 181f49a0f2
21 changed files with 548 additions and 280 deletions

19
media/mixins.py Normal file
View File

@@ -0,0 +1,19 @@
from django.contrib.contenttypes.models import ContentType
from django.db.models import QuerySet
class PhotoableModel:
"""Mixin for models that can have photos attached."""
def get_photos(self) -> QuerySet:
"""Get photos for this instance."""
from media.models import Photo
ct = ContentType.objects.get_for_model(self.__class__)
return Photo.objects.filter(content_type=ct, object_id=self.pk)
def add_photo(self, photo: 'Photo') -> None:
"""Add a photo to this instance."""
from media.models import Photo
ct = ContentType.objects.get_for_model(self.__class__)
photo.content_type = ct
photo.object_id = self.pk
photo.save()