Skip to content

Commit eef3697

Browse files
committed
fix: ContentMetadata.bulk_update() changes the modified value
1 parent 0c83224 commit eef3697

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

enterprise_catalog/apps/catalog/models.py

+21
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,25 @@ def get_xapi_activity_id(self, content_resource, content_key):
493493
return xapi_activity_id
494494

495495

496+
class ContentMetadataManager(models.Manager):
497+
"""
498+
Customer manager for ContentMetadata that forces the `modified` field
499+
to be updated during `bulk_update()`.
500+
"""
501+
502+
def bulk_update(self, objs, fields, batch_size=None):
503+
"""
504+
Updates the `modified` time of each object, and then
505+
does the usual bulk update, with `modified` as also
506+
a field to save.
507+
"""
508+
last_modified = localized_utcnow()
509+
for obj in objs:
510+
obj.modified = last_modified
511+
fields += ['modified']
512+
513+
super().bulk_update(objs, fields, batch_size=None)
514+
496515
class ContentMetadata(TimeStampedModel):
497516
"""
498517
Stores the JSON metadata for a piece of content, such as a course, course run, or program.
@@ -556,6 +575,8 @@ class ContentMetadata(TimeStampedModel):
556575

557576
history = HistoricalRecords()
558577

578+
objects = ContentMetadataManager()
579+
559580
class Meta:
560581
verbose_name = _("Content Metadata")
561582
verbose_name_plural = _("Content Metadata")

0 commit comments

Comments
 (0)