diff --git a/openverse_api/catalog/api/migrations/0039_audio_set_thumbs.py b/openverse_api/catalog/api/migrations/0039_audio_set_thumbs.py new file mode 100644 index 000000000..83ff131c7 --- /dev/null +++ b/openverse_api/catalog/api/migrations/0039_audio_set_thumbs.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.7 on 2021-10-11 15:48 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0038_filetypes'), + ] + + operations = [ + migrations.AddField( + model_name='audioset', + name='thumbnail', + field=models.URLField(blank=True, help_text='The thumbnail for the media.', max_length=1000, null=True), + ), + ] diff --git a/openverse_api/catalog/api/migrations/0040_nullable_urls.py b/openverse_api/catalog/api/migrations/0040_nullable_urls.py new file mode 100644 index 000000000..d884ea818 --- /dev/null +++ b/openverse_api/catalog/api/migrations/0040_nullable_urls.py @@ -0,0 +1,28 @@ +# Generated by Django 3.2.7 on 2021-10-11 15:52 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0039_audio_set_thumbs'), + ] + + operations = [ + migrations.AlterField( + model_name='audio', + name='url', + field=models.URLField(blank=True, help_text='The actual URL to the media file.', max_length=1000, null=True, unique=True), + ), + migrations.AlterField( + model_name='audioset', + name='url', + field=models.URLField(blank=True, help_text='The actual URL to the media file.', max_length=1000, null=True, unique=True), + ), + migrations.AlterField( + model_name='image', + name='url', + field=models.URLField(blank=True, help_text='The actual URL to the media file.', max_length=1000, null=True, unique=True), + ), + ] diff --git a/openverse_api/catalog/api/models/media.py b/openverse_api/catalog/api/models/media.py index 415abbb46..6e52490bc 100644 --- a/openverse_api/catalog/api/models/media.py +++ b/openverse_api/catalog/api/models/media.py @@ -25,10 +25,6 @@ class AbstractMedia(IdentifierMixin, MediaMixin, OpenLedgerModel): information common to all media types indexed by Openverse. """ - thumbnail = models.URLField( - max_length=1000, blank=True, null=True, help_text="The thumbnail for the media." - ) - watermarked = models.BooleanField(blank=True, null=True) license = models.CharField(max_length=50) diff --git a/openverse_api/catalog/api/models/mixins.py b/openverse_api/catalog/api/models/mixins.py index 898d2094e..5607bcbb3 100644 --- a/openverse_api/catalog/api/models/mixins.py +++ b/openverse_api/catalog/api/models/mixins.py @@ -53,6 +53,11 @@ class MediaMixin(models.Model): creator = models.CharField(max_length=2000, blank=True, null=True) creator_url = models.URLField(max_length=2000, blank=True, null=True) + # Because all forms of media have a thumbnail for visual representation + thumbnail = models.URLField( + max_length=1000, blank=True, null=True, help_text="The thumbnail for the media." + ) + class Meta: abstract = True @@ -64,7 +69,11 @@ class FileMixin(models.Model): """ url = models.URLField( - unique=True, max_length=1000, help_text="The actual URL to the media file." + unique=True, + max_length=1000, + help_text="The actual URL to the media file.", + blank=True, + null=True, ) filesize = models.IntegerField( blank=True, diff --git a/openverse_api/catalog/api/views/audio_views.py b/openverse_api/catalog/api/views/audio_views.py index 266626a7f..61ecc0bde 100644 --- a/openverse_api/catalog/api/views/audio_views.py +++ b/openverse_api/catalog/api/views/audio_views.py @@ -65,7 +65,7 @@ def thumbnail(self, request, *_, **__): image_url = None if thumbnail := audio.thumbnail: image_url = thumbnail - elif audio.audio_set and (thumbnail := audio.audio_set.url): + elif audio.audio_set and (thumbnail := audio.audio_set.thumbnail): image_url = thumbnail if not image_url: raise get_api_exception("Could not find artwork.", 404)