moviewyrm/fedireads/models/shelf.py

41 lines
1.1 KiB
Python
Raw Normal View History

2020-03-07 06:56:44 +00:00
''' puttin' books on shelves '''
from django.db import models
2020-05-10 20:38:47 +00:00
from .base_model import FedireadsModel
2020-03-07 06:56:44 +00:00
class Shelf(FedireadsModel):
name = models.CharField(max_length=100)
identifier = models.CharField(max_length=100)
user = models.ForeignKey('User', on_delete=models.PROTECT)
editable = models.BooleanField(default=True)
books = models.ManyToManyField(
'Edition',
2020-03-07 06:56:44 +00:00
symmetrical=False,
through='ShelfBook',
through_fields=('shelf', 'book')
)
def get_remote_id(self):
''' shelf identifier instead of id '''
base_path = self.user.remote_id
return '%s/shelf/%s' % (base_path, self.identifier)
2020-03-07 06:56:44 +00:00
class Meta:
unique_together = ('user', 'identifier')
class ShelfBook(FedireadsModel):
# many to many join table for books and shelves
book = models.ForeignKey('Edition', on_delete=models.PROTECT)
2020-03-07 06:56:44 +00:00
shelf = models.ForeignKey('Shelf', on_delete=models.PROTECT)
added_by = models.ForeignKey(
'User',
blank=True,
null=True,
on_delete=models.PROTECT
)
class Meta:
unique_together = ('book', 'shelf')