Reputation: 21
Error - client.Client.status: (fields.E005) 'choices' must be an iterable containing (actual value, human readable name) tuples.
Here is the code:
class Client(models.Model):
client_name = models.CharField(max_length=300)
address = models.CharField(max_length=300)
start_date = models.DateField(default=datetime.now, blank=True)
end_date = models.DateField(default=datetime.now, blank=True)
created = models.DateTimeField(auto_now_add=True)
ACTIVE = 'AC',
TO_EXPIRE = 'TE',
EXPIRED = 'EX',
STATUS_CHOICES = [
(ACTIVE, 'Active'),
(TO_EXPIRE, 'To Expire'),
(EXPIRED, 'Expired'),
]
status = models.CharField(max_length=2, choices=STATUS_CHOICES, default=ACTIVE)
user = models.ForeignKey(User, on_delete=models.CASCADE)
Upvotes: 1
Views: 98
Reputation: 5931
Your issue is simple, but subtle:
ACTIVE = 'AC',
TO_EXPIRE = 'TE',
EXPIRED = 'EX',
You must remove the trailing commas here. Python interprets these as tuples of length one with the 0 index value equal to the string.
eg
ACTIVE = ('AC',)
# is equivalent to
ACTIVE = 'AC',
What you want here is simply ACTIVE = 'AC'
Upvotes: 6