diff --git a/catalog/book/models.py b/catalog/book/models.py index 7f118188..e70335e9 100644 --- a/catalog/book/models.py +++ b/catalog/book/models.py @@ -62,6 +62,7 @@ class EditionSchema(EditionInSchema, BaseSchema): class Edition(Item): + works: models.ManyToManyField["Work", "Edition"] category = ItemCategory.Book url_path = "book" diff --git a/catalog/common/models.py b/catalog/common/models.py index 3c7ed647..fd03ae91 100644 --- a/catalog/common/models.py +++ b/catalog/common/models.py @@ -23,6 +23,7 @@ from .utils import DEFAULT_ITEM_COVER, item_cover_path, resource_cover_path if TYPE_CHECKING: + from journal.models import Collection from users.models import User @@ -247,6 +248,7 @@ class ItemSchema(BaseSchema, ItemInSchema): class Item(PolymorphicModel, SoftDeleteMixin): + collections: QuerySet["Collection"] url_path = "item" # subclass must specify this type = None # subclass must specify this child_class = None # subclass may specify this to allow link to parent item diff --git a/catalog/podcast/models.py b/catalog/podcast/models.py index d0f3b348..b1b1d7fa 100644 --- a/catalog/podcast/models.py +++ b/catalog/podcast/models.py @@ -26,6 +26,7 @@ class PodcastSchema(PodcastInSchema, BaseSchema): class Podcast(Item): + episodes: models.QuerySet["PodcastEpisode"] category = ItemCategory.Podcast child_class = "PodcastEpisode" url_path = "podcast" diff --git a/catalog/views.py b/catalog/views.py index 86574722..40b0a1c7 100644 --- a/catalog/views.py +++ b/catalog/views.py @@ -129,7 +129,7 @@ def retrieve(request, item_path, item_uuid): def episode_data(request, item_uuid): - item = get_object_or_404(Item, uid=get_uuid_or_404(item_uuid)) + item = get_object_or_404(Podcast, uid=get_uuid_or_404(item_uuid)) qs = item.episodes.all().order_by("-pub_date") if request.GET.get("last"): qs = qs.filter(pub_date__lt=request.GET.get("last")) diff --git a/journal/models/collection.py b/journal/models/collection.py index bc637d37..420893e0 100644 --- a/journal/models/collection.py +++ b/journal/models/collection.py @@ -40,6 +40,7 @@ def ap_object(self): class Collection(List): + members: models.QuerySet[CollectionMember] url_path = "collection" MEMBER_CLASS = CollectionMember catalog_item = models.OneToOneField( diff --git a/journal/models/common.py b/journal/models/common.py index 77c6c80e..40a71048 100644 --- a/journal/models/common.py +++ b/journal/models/common.py @@ -21,6 +21,8 @@ if TYPE_CHECKING: from takahe.models import Post + from .like import Like + class VisibilityType(models.IntegerChoices): Public = 0, _("Public") @@ -112,6 +114,7 @@ def q_item_in_category(item_category: ItemCategory): class Piece(PolymorphicModel, UserOwnedObjectMixin): + likes: models.QuerySet["Like"] url_path = "p" # subclass must specify this uid = models.UUIDField(default=uuid.uuid4, editable=False, db_index=True) local = models.BooleanField(default=True) diff --git a/journal/models/mixins.py b/journal/models/mixins.py index 8c7da950..41787ddb 100644 --- a/journal/models/mixins.py +++ b/journal/models/mixins.py @@ -18,7 +18,9 @@ class UserOwnedObjectMixin: """ if TYPE_CHECKING: - owner: ForeignKey[APIdentity, Piece] + owner: ForeignKey[Piece, APIdentity] + # owner: ForeignKey[APIdentity, Piece] + owner_id: int visibility: int def is_visible_to( diff --git a/journal/models/shelf.py b/journal/models/shelf.py index 40e7df1f..494aae7f 100644 --- a/journal/models/shelf.py +++ b/journal/models/shelf.py @@ -378,6 +378,7 @@ class Shelf(List): class Meta: unique_together = [["owner", "shelf_type"]] + members: models.QuerySet[ShelfMember] MEMBER_CLASS = ShelfMember items = models.ManyToManyField(Item, through="ShelfMember", related_name="+") shelf_type = models.CharField( diff --git a/takahe/utils.py b/takahe/utils.py index 00f37a92..20ebbf3c 100644 --- a/takahe/utils.py +++ b/takahe/utils.py @@ -533,7 +533,8 @@ def visibility_n2t(visibility: int, post_public_mode: int) -> Visibilities: @staticmethod def post_collection(collection: "Collection"): existing_post = collection.latest_post - user = collection.owner.user + owner: APIdentity = collection.owner + user = owner.user if not user: raise ValueError(f"Cannot find user for collection {collection}") visibility = Takahe.visibility_n2t(