python - isinstance() arg 2 must be an type or tuple of types error in Django
问题描述
使用 Django Rest Framework 时,我不断收到此错误:
isinstance() arg 2 must be a type or tuple of types
这是我的模型:
class mymodel(models.Model):
firstfield = models.ArrayModelField(models.FloatField())
secondfield = models.ArrayModelField(models.FloatField())
def save(self, *args, using=None, **kwargs):
super(mymodel, self).save(*args, using='mydb', **kwargs)
这是我的数据的样子:
id: 'some id here'
firstfield: ['somefloat', 'somefloat'], ['another float', 'another float'] ...
secondfield: ['somefloat', 'somefloat'], ['another float', 'another float'] ...
我认为问题出在我的 MongoDB 数据上。基本上,firstfield
'secondfield' 都是列表,包含其他列表,每个列表都有两个浮点数。解决此问题的每一个建议都值得赞赏
解决方案
ArrayModelField
[Djongo-doc]上的文档说:
使用 MongoDB,在父文档中可以有一组嵌入文档。您可以在父模型中创建嵌入数组/模型列表并将其直接存储到 MongoDB 中。
所以这用于存储模型对象的集合,而不是浮点数等。您可以为此使用ListField
[Djongo-doc]。
推荐阅读
- java - JPA 标准规范 - 多选与分组返回所有列
- database - 在 Pycharm 中的运行之间缓存数据库查询
- google-cloud-platform - gcloud run deploy 在本地工作,但不在 bitbucket 管道中
- php - 在 PHP 中按范围使用适当的公式
- javascript - 如何从 div 类 Cypress 中获取文本
- linux-kernel - CONFIG_RT_GROUP_SCHED 和 PREEMPT_RT 之间的区别?
- mysql - 如何在 MySQL/MariaDB 中创建比当前登录用户具有更多权限的用户?
- python - 如何在 Python 中实现 Chebyshev 2 过滤器
- spring-integration - Spring Integration Poller 在没有应用程序重启的情况下无法在 Pivotal Cloud Foundry 中工作
- asp.net-mvc - MVC,以表格形式获取现有数据的编辑视图问题