Reuse existing files as previews, icons or featured images #161
@ -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
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user