Reuse existing files as previews, icons or featured images #161

Merged
Anna Sirota merged 11 commits from files-allow-reuse-between-ext into main 2024-06-04 12:23:26 +02:00
Showing only changes of commit a3fa05c355 - Show all commits

View File

@ -64,19 +64,12 @@ class AddPreviewFileForm(files.forms.BaseMediaFileForm):
"""Save Preview from the cleaned form data.""" """Save Preview from the cleaned form data."""
instance = super().save(*args, **kwargs) instance = super().save(*args, **kwargs)
# Create extension preview and save caption to it # Create extension preview and save caption to it, ignore duplicate records
extensions.models.Preview.objects.bulk_create( extensions.models.Preview.objects.get_or_create(
[ file=instance,
extensions.models.Preview( extension=self.extension,
file=instance, defaults={'caption': self.cleaned_data['caption']},
caption=self.cleaned_data['caption'],
extension=self.extension,
)
],
ignore_conflicts=True,
update_conflicts=False,
) )
return instance return instance