由于原因不明,我的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'])
提前感谢您的帮助。
答案 0 :(得分:7)
你忘了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'])