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(
|
||||||
[
|
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
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user