Let users create shelves

This commit is contained in:
Mouse Reeve
2020-11-10 14:52:04 -08:00
parent c3fe8e041a
commit 408ca6609c
6 changed files with 80 additions and 21 deletions

View File

@ -1,4 +1,5 @@
''' puttin' books on shelves '''
import re
from django.db import models
from bookwyrm import activitypub
@ -23,6 +24,15 @@ class Shelf(OrderedCollectionMixin, BookWyrmModel):
through_fields=('shelf', 'book')
)
def save(self, *args, **kwargs):
''' set the identifier '''
saved = super().save(*args, **kwargs)
if not self.identifier:
slug = re.sub(r'[^\w]', '', self.name)
self.identifier = '%s-%d' % (slug, self.id)
return super().save(*args, **kwargs)
return saved
@property
def collection_queryset(self):
''' list of books for this shelf, overrides OrderedCollectionMixin '''