bookwyrm/bookwyrm/models/author.py

44 lines
1.6 KiB
Python
Raw Normal View History

''' database schema for info about authors '''
from django.db import models
from django.utils import timezone
from bookwyrm import activitypub
2020-11-28 21:40:09 +00:00
from bookwyrm.settings import DOMAIN
2020-11-30 22:40:26 +00:00
from .base_model import ActivitypubMixin, BookWyrmModel
from . import fields
class Author(ActivitypubMixin, BookWyrmModel):
''' basic biographic info '''
origin_id = models.CharField(max_length=255, null=True)
2020-12-12 21:39:55 +00:00
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)
2020-12-13 02:06:48 +00:00
wikipedia_link = fields.CharField(
max_length=255, blank=True, null=True, deduplication_field=True)
# idk probably other keys would be useful here?
2020-11-30 22:40:26 +00:00
born = fields.DateTimeField(blank=True, null=True)
died = fields.DateTimeField(blank=True, null=True)
name = fields.CharField(max_length=255, deduplication_field=True)
2020-11-30 22:40:26 +00:00
aliases = fields.ArrayField(
models.CharField(max_length=255), blank=True, default=list
)
2020-12-17 00:47:05 +00:00
bio = fields.HtmlField(null=True, blank=True)
2020-11-28 21:40:09 +00:00
def save(self, *args, **kwargs):
''' handle remote vs origin ids '''
if self.id:
2020-11-28 21:40:09 +00:00
self.remote_id = self.get_remote_id()
else:
2020-11-28 21:40:09 +00:00
self.origin_id = self.remote_id
self.remote_id = None
2020-11-28 21:40:09 +00:00
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)
2020-11-28 21:40:09 +00:00
activity_serializer = activitypub.Author