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."""
|
"""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(
|
||||||
[
|
|
||||||
extensions.models.Preview(
|
|
||||||
file=instance,
|
file=instance,
|
||||||
caption=self.cleaned_data['caption'],
|
|
||||||
extension=self.extension,
|
extension=self.extension,
|
||||||
|
defaults={'caption': self.cleaned_data['caption']},
|
||||||
)
|
)
|
||||||
],
|
|
||||||
ignore_conflicts=True,
|
|
||||||
update_conflicts=False,
|
|
||||||
)
|
|
||||||
|
|
||||||
return instance
|
return instance
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user