从其他应用程序获取json字段的所有对象

2024-04-20 14:55:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个带有json字段的模型类:

class Collection(models.Model, AdminImageable):
    units = JSONField(verbose_name='element collection')

我正在尝试在其他应用程序中获取此字段的所有对象,并在my views.py中使用此类代码

qwe = Collection.objects.filter(pagecollection__page_id=sluglist[0]).order_by('units') l = []
for col in qwe:
    l.append(
        apps.get_model(col.units['namespace'], col.units['model'], require_ready=True)
        )

但是,我有一个错误——列表索引必须是整数或片,而不是str


Tags: name模型jsonverbosemodelmodelscolelement