Remove sync fields and share fields between book and author

This commit is contained in:
Mouse Reeve
2020-12-21 12:17:18 -08:00
parent aac264c998
commit cfa1a1b42c
6 changed files with 84 additions and 49 deletions

View File

@ -1,21 +1,15 @@
''' database schema for info about authors '''
from django.db import models
from django.utils import timezone
from bookwyrm import activitypub
from bookwyrm.settings import DOMAIN
from .base_model import ActivitypubMixin, BookWyrmModel
from .book import BookDataModel
from . import fields
class Author(ActivitypubMixin, BookWyrmModel):
class Author(BookDataModel):
''' basic biographic info '''
origin_id = models.CharField(max_length=255, null=True)
openlibrary_key = fields.CharField(
max_length=255, blank=True, null=True, deduplication_field=True)
sync = models.BooleanField(default=True)
last_sync_date = models.DateTimeField(default=timezone.now)
wikipedia_link = fields.CharField(
max_length=255, blank=True, null=True, deduplication_field=True)
# idk probably other keys would be useful here?
@ -27,15 +21,6 @@ class Author(ActivitypubMixin, BookWyrmModel):
)
bio = fields.HtmlField(null=True, blank=True)
def save(self, *args, **kwargs):
''' handle remote vs origin ids '''
if self.id:
self.remote_id = self.get_remote_id()
else:
self.origin_id = self.remote_id
self.remote_id = None
return super().save(*args, **kwargs)
def get_remote_id(self):
''' editions and works both use "book" instead of model_name '''
return 'https://%s/author/%s' % (DOMAIN, self.id)