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."""
instance = super().save(*args, **kwargs)
# Create extension preview and save caption to it
extensions.models.Preview.objects.bulk_create(
[
extensions.models.Preview(
file=instance,
caption=self.cleaned_data['caption'],
extension=self.extension,
)
],
ignore_conflicts=True,
update_conflicts=False,
# Create extension preview and save caption to it, ignore duplicate records
extensions.models.Preview.objects.get_or_create(
file=instance,
extension=self.extension,
defaults={'caption': self.cleaned_data['caption']},
)
return instance