django - 类型对象没有属性 'get_or_create'

标签 django django-models

由于未知原因,我的 Django 模型中只有一个(18 个)抛出错误“类型对象‘LidarReading’没有属性‘get_or_create’”。模型声明如下。

class LidarReading(models.Model):
    value = models.DecimalField(max_digits=10, decimal_places=2)
    roll = models.DecimalField(max_digits=12, decimal_places=4)
    pitch = models.DecimalField(max_digits=12, decimal_places=4)
    yaw = models.DecimalField(max_digits=12, decimal_places=4)
    coordinates = models.ForeignKey('FlightCoordinate', models.SET_NULL, blank=True, null=True)

    created = models.DateTimeField(auto_now_add=True, blank=True, null=True)
    modified = models.DateTimeField(auto_now=True)

调用 Django command如下(请注意,'flight_coordinate' 是使用上面的 get_or_create 创建的 FlightCoordinate 模型对象):
lidar, created = LidarReading.get_or_create(value=t['lidarreading_value'],
    roll=t['lidarreading_roll'],
    pitch=t['lidarreading_pitch'],
    yaw=t['lidarreading_yaw'],
    coordinates=flight_coordinate,
    created=t['lidarreading_created'])

预先感谢您的帮助。

最佳答案

你忘了objects

lidar, created = LidarReading.objects.get_or_create(value=t['lidarreading_value'],
    roll=t['lidarreading_roll'],
    pitch=t['lidarreading_pitch'],
    yaw=t['lidarreading_yaw'],
    coordinates=flight_coordinate,
    created=t['lidarreading_created'])

关于django - 类型对象没有属性 'get_or_create',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41108194/

相关文章:

python - 具有多个站点的 django 应用程序 - 如何限制员工的访问

javascript - Django 中的弹出窗体(Jquery)

python - django send_mail 来自查询集

python - 使用字典在模型中创建对象时出现 Django TypeError

python - 更新继承的django模型字段属性?

Django-Weasyprint 图像问题

python - 自定义用户和表单的实现

python - Django GROUP BY strftime 日期格式

Django 独特的批量插入

python - 查找日期和时间距现在不到 24 小时的对象