Use Media.has_metadata in Media.save function

This commit is contained in:
tcely 2025-04-18 19:58:29 -04:00 committed by GitHub
parent 98c031ed5f
commit 60ffc4cdc8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -830,14 +830,21 @@ class Media(models.Model):
update_fields = {'media_file', 'skip'}.union(update_fields)
# Trigger an update of derived fields from metadata
if update_fields is None or 'metadata' in update_fields:
update_md = (
self.created and
self.has_metadata and
(
update_fields is None or
'metadata' in update_fields
)
)
if update_md:
setattr(self, '_cached_metadata_dict', None)
if self.metadata:
self.title = self.metadata_title[:200]
self.duration = self.metadata_duration
if update_fields is not None and "metadata" in update_fields:
# If only some fields are being updated, make sure we update title and duration if metadata changes
update_fields = {"title", "duration"}.union(update_fields)
if update_fields is not None:
# If only some fields are being updated, make sure we update title and duration if metadata changes
update_fields = {"title", "duration"}.union(update_fields)
super().save(
force_insert=force_insert,