From b0ea31f2a9c9fc50e75352209da48951aef8446b Mon Sep 17 00:00:00 2001 From: Joel Bradshaw Date: Wed, 13 Jan 2021 23:44:44 -0800 Subject: [PATCH] Add order for shelf books to satisfy warning I believe this will sort books by order they were added to the shelf, which seems reasonable. Should add some tests to make sure though. --- bookwyrm/models/base_model.py | 2 ++ bookwyrm/models/shelf.py | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/bookwyrm/models/base_model.py b/bookwyrm/models/base_model.py index 430097c0..1253e7a5 100644 --- a/bookwyrm/models/base_model.py +++ b/bookwyrm/models/base_model.py @@ -281,4 +281,6 @@ class OrderedCollectionMixin(OrderedCollectionPageMixin): def to_activity(self, **kwargs): ''' an ordered collection of the specified model queryset ''' + if not self.collection_queryset.ordered: + raise RuntimeError('collection_queryset must be ordered') return self.to_ordered_collection(self.collection_queryset, **kwargs) diff --git a/bookwyrm/models/shelf.py b/bookwyrm/models/shelf.py index a06f78dc..84575137 100644 --- a/bookwyrm/models/shelf.py +++ b/bookwyrm/models/shelf.py @@ -39,7 +39,7 @@ class Shelf(OrderedCollectionMixin, BookWyrmModel): @property def collection_queryset(self): ''' list of books for this shelf, overrides OrderedCollectionMixin ''' - return self.books.all() + return self.books.all().order_by('shelfbook') def get_remote_id(self): ''' shelf identifier instead of id ''' @@ -90,3 +90,4 @@ class ShelfBook(ActivitypubMixin, BookWyrmModel): ''' an opinionated constraint! you can't put a book on shelf twice ''' unique_together = ('book', 'shelf') + ordering = ('-created_date',)