我有一个雷达模型,它需要有4种可能的模式。我遵循了django网站(https://docs.djangoproject.com/en/1.11/ref/models/fields/#choices)上的文档。但是我仍然遇到错误。我将在下面发布我的模型文件。如果您认为我可能需要发布其他任何代码,请告诉我。
from django.db import models
# Create your models here.
class Radar(models.Model):
id = models.AutoField(primary_key=True)
SCAN = "SC"
ON = "ON"
OFF = "OF"
STANDBY = "ST"
MODE_CHOICES = (
(SCAN, "scan"),
(ON, "on"),
(OFF, "off"),
(STANDBY, "standby"),
)
mode_choice = models.CharField(
max_length=2,
choice=MODE_CHOICES,
default=OFF,
)
ip_address = models.CharField(max_length=200)
start_azimuth_angle = models.FloatField(default=0)
end_azimuth_angle = models.FloatField(default=0)
azimuth_scan_speed = models.FloatField(default=0)
azimuth_increment = models.FloatField(default=0)
start_elevation_angle = models.FloatField(default=0)
end_elevation_angle = models.FloatField(default=0)
elevation_scan_speed = models.FloatField(default=0)
elevation_increment = models.FloatField(default=0)
def __str__(self):
string = 'RadarID : %s ip: %s ' % (self.id, self.ip_address)
return string
答案 0 :(得分:1)
您的代码中有错字:
正确的参数是choice
,而不是choices
mode_choice = models.CharField(
max_length=2,
choices=MODE_CHOICES,
default=OFF,
)
答案 1 :(得分:0)
option是options。将选择更改为选择。 https://docs.djangoproject.com/en/2.0/ref/models/fields/#choices