Reputation: 137
I have a model that is a radar, and it needs to have 4 possible modes. I followed the documentation on the django website (https://docs.djangoproject.com/en/1.11/ref/models/fields/#choices). However I am still getting an error. I will post my model file down below. If you think I might need to post any other code let me know.
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
Upvotes: 0
Views: 1137
Reputation: 2159
option for using choices with CharField is choices. change choice to choices. https://docs.djangoproject.com/en/2.0/ref/models/fields/#choices
Upvotes: 0
Reputation: 8525
You have a typo in your code:
instead of choice
, the correct argument is choices
mode_choice = models.CharField(
max_length=2,
choices=MODE_CHOICES,
default=OFF,
)
Upvotes: 1