Video media_data: Change layout in the mongo world
Change the media_data for video from entry.media_data["video"] to use entry.media_data directly. Also start a bare MediaEntry.media_data_init(**kwargs) method for setting up the media_data and possibly initialising it with kwargs.
This commit is contained in:
@@ -139,3 +139,17 @@ def remove_calculated_html(database):
|
||||
drop_table_field(database, 'users', 'bio_html')
|
||||
drop_table_field(database, 'media_entries', 'description_html')
|
||||
drop_table_field(database, 'media_comments', 'content_html')
|
||||
|
||||
@RegisterMigration(10)
|
||||
def convert_video_media_data(database):
|
||||
"""
|
||||
Move media_data["video"] directly into media_data
|
||||
"""
|
||||
collection = database['media_entries']
|
||||
target = collection.find(
|
||||
{'media_data.video': {'$exists': True}})
|
||||
|
||||
for document in target:
|
||||
assert len(document['media_data']) == 1
|
||||
document['media_data'] = document['media_data']['video']
|
||||
collection.save(document)
|
||||
|
||||
@@ -220,6 +220,9 @@ class MediaEntry(Document, MediaEntryMixin):
|
||||
|
||||
id = MongoPK()
|
||||
|
||||
def media_data_init(self, **kwargs):
|
||||
self.media_data.update(kwargs)
|
||||
|
||||
def get_comments(self, ascending=False):
|
||||
if ascending:
|
||||
order = ASCENDING
|
||||
|
||||
Reference in New Issue
Block a user