From 88e470571761eae9275d3bcbc262c2a378312f5b Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 23 Nov 2020 20:42:05 -0800 Subject: [PATCH] Use attachment database table --- bookwyrm/migrations/0012_attachment.py | 28 +++++++++++++++++++++++ bookwyrm/migrations/0012_status_images.py | 19 --------------- bookwyrm/models/status.py | 15 ++++++++---- 3 files changed, 38 insertions(+), 24 deletions(-) create mode 100644 bookwyrm/migrations/0012_attachment.py delete mode 100644 bookwyrm/migrations/0012_status_images.py diff --git a/bookwyrm/migrations/0012_attachment.py b/bookwyrm/migrations/0012_attachment.py new file mode 100644 index 000000000..47b2885b8 --- /dev/null +++ b/bookwyrm/migrations/0012_attachment.py @@ -0,0 +1,28 @@ +# Generated by Django 3.0.7 on 2020-11-24 00:41 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('bookwyrm', '0011_auto_20201113_1727'), + ] + + operations = [ + migrations.CreateModel( + name='Attachment', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('created_date', models.DateTimeField(auto_now_add=True)), + ('updated_date', models.DateTimeField(auto_now=True)), + ('remote_id', models.CharField(max_length=255, null=True)), + ('image', models.ImageField(blank=True, null=True, upload_to='status/')), + ('status', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='items', to='bookwyrm.Status')), + ], + options={ + 'abstract': False, + }, + ), + ] diff --git a/bookwyrm/migrations/0012_status_images.py b/bookwyrm/migrations/0012_status_images.py deleted file mode 100644 index 3b440bfd9..000000000 --- a/bookwyrm/migrations/0012_status_images.py +++ /dev/null @@ -1,19 +0,0 @@ -# Generated by Django 3.0.7 on 2020-11-23 20:44 - -import bookwyrm.utils.fields -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('bookwyrm', '0011_auto_20201113_1727'), - ] - - operations = [ - migrations.AddField( - model_name='status', - name='images', - field=bookwyrm.utils.fields.ArrayField(base_field=models.ImageField(upload_to='status/'), default=list, size=None), - ), - ] diff --git a/bookwyrm/models/status.py b/bookwyrm/models/status.py index 50e46bd6f..4136e0853 100644 --- a/bookwyrm/models/status.py +++ b/bookwyrm/models/status.py @@ -5,7 +5,6 @@ from django.db import models from model_utils.managers import InheritanceManager from bookwyrm import activitypub -from bookwyrm.utils.fields import ArrayField from .base_model import ActivitypubMixin, OrderedCollectionPageMixin from .base_model import ActivityMapping, BookWyrmModel, PrivacyLevels from .base_model import tag_formatter @@ -18,10 +17,6 @@ class Status(OrderedCollectionPageMixin, BookWyrmModel): mention_users = models.ManyToManyField('User', related_name='mention_user') mention_books = models.ManyToManyField( 'Edition', related_name='mention_book') - images = ArrayField( - models.ImageField(upload_to='status/'), - default=list - ) local = models.BooleanField(default=True) privacy = models.CharField( max_length=255, @@ -150,6 +145,16 @@ class Status(OrderedCollectionPageMixin, BookWyrmModel): super().save(*args, **kwargs) +class Attachment(BookWyrmModel): + ''' an image (or, in the future, video etc) associated with a status ''' + status = models.ForeignKey( + 'Status', + on_delete=models.CASCADE, + related_name='items' + ) + image = models.ImageField(upload_to='status/', null=True, blank=True) + + class GeneratedNote(Status): ''' these are app-generated messages about user activity ''' @property