我有带有指定模型和序列化程序类的普通 ListAPIView。我需要在列表末尾添加一项。此项应手动创建(无查询集),并且应与其他项具有相同的结构。
我的数据迁移文件中有此文件:
def set_target_user(apps, schema_editor):
LogEntry = apps.get_model('auditlog', 'LogEntry')
ContentType = apps.get_model('contenttypes', 'ContentType')
for entry in LogEntry.objects.filter(target_user=None):
ct = ContentType.objects.get(id=entry.content_type.id)
model = ct.model_class()
Run Code Online (Sandbox Code Playgroud)
我提到了AttributeError。但是它在其他模块(不是migratins)中也能很好地工作。任何想法如何克服这个?