Cleaning up model fields
This commit is contained in:
parent
906aa317c9
commit
5cd43d53ba
8 changed files with 50 additions and 62 deletions
|
@ -1,23 +1,13 @@
|
|||
''' database schema for the whole dang thing '''
|
||||
''' database schema for books and shelves '''
|
||||
from django.db import models
|
||||
from model_utils.managers import InheritanceManager
|
||||
from django.dispatch import receiver
|
||||
from django.contrib.auth.models import AbstractUser
|
||||
from django.core.exceptions import ValidationError
|
||||
from Crypto import Random
|
||||
from Crypto.PublicKey import RSA
|
||||
import re
|
||||
|
||||
from fedireads.settings import DOMAIN, OL_URL
|
||||
from fedireads.utils.fields import JSONField
|
||||
|
||||
|
||||
class Shelf(models.Model):
|
||||
activitypub_id = models.CharField(max_length=255)
|
||||
identifier = models.CharField(max_length=255, unique=True)
|
||||
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)
|
||||
shelf_type = models.CharField(default='custom', max_length=100)
|
||||
books = models.ManyToManyField(
|
||||
'Book',
|
||||
symmetrical=False,
|
||||
|
@ -28,18 +18,7 @@ class Shelf(models.Model):
|
|||
updated_date = models.DateTimeField(auto_now=True)
|
||||
|
||||
class Meta:
|
||||
unique_together = ('user', 'name')
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if not self.identifier:
|
||||
self.identifier = '%s_%s' % (
|
||||
self.user.localname,
|
||||
re.sub(r'\W', '-', self.name).lower()
|
||||
)
|
||||
if not self.activitypub_id:
|
||||
self.activitypub_id = 'https://%s/shelf/%s' % \
|
||||
(DOMAIN, self.identifier)
|
||||
super().save(*args, **kwargs)
|
||||
unique_together = ('user', 'identifier')
|
||||
|
||||
|
||||
class ShelfBook(models.Model):
|
||||
|
@ -52,7 +31,7 @@ class ShelfBook(models.Model):
|
|||
null=True,
|
||||
on_delete=models.PROTECT
|
||||
)
|
||||
added_date = models.DateTimeField(auto_now_add=True)
|
||||
created_date = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
class Meta:
|
||||
unique_together = ('book', 'shelf')
|
||||
|
@ -60,7 +39,6 @@ class ShelfBook(models.Model):
|
|||
|
||||
class Book(models.Model):
|
||||
''' a non-canonical copy of a work (not book) from open library '''
|
||||
activitypub_id = models.CharField(max_length=255)
|
||||
openlibrary_key = models.CharField(max_length=255, unique=True)
|
||||
data = JSONField()
|
||||
authors = models.ManyToManyField('Author')
|
||||
|
@ -81,12 +59,9 @@ class Book(models.Model):
|
|||
added_date = models.DateTimeField(auto_now_add=True)
|
||||
updated_date = models.DateTimeField(auto_now=True)
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
self.activitypub_id = '%s%s' % (OL_URL, self.openlibrary_key)
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
|
||||
class Author(models.Model):
|
||||
''' copy of an author from OL '''
|
||||
openlibrary_key = models.CharField(max_length=255)
|
||||
data = JSONField()
|
||||
added_date = models.DateTimeField(auto_now_add=True)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue