【发布时间】:2021-06-02 08:43:06
【问题描述】:
我想为一个媒体对象保存 x 个 MediaStreams。所以我在这里有一个一对多的关系(ForeignKey),但我不确定我如何才能做到这一点,因为目前总是保存相同的流,而不是预期的 5 个不同的流。我需要在哪里放置“i”才能在 for 循环中创建对象?
for i in clean_result['streams']:
new_stream = MediaStreams.objects.create(index=index_value, stream_bitrate=streambitrate_value,
codec_name=codec_name_value, codec_type=codec_type_value,
width=width_value, height=height_value,
channel_layout=channel_layout_value, language=language_value,
media=new_object)
new_stream.save()
目前只保存索引 5 而不是 0-5 - clean_result['streams']['index']。
提前致谢
【问题讨论】:
-
你能添加堆栈跟踪吗?
-
@DeanElliott 对不起,但现在我没有这个问题了,所以没有堆栈跟踪......我仍然无法通过 dict 循环。
标签: python django for-loop model