Choices function in Django Models giving Error: Select a valid choice. 2 is not one of the available choices

874 Views Asked by At

Unable to set rating choice through Django admin console Error: Select a valid choice. 2 is not one of the available choices.

models.py

    from model_utils import Choices

class Course_Feedback(models.Model):
    course = models.ForeignKey(Course, on_delete=models.PROTECT, related_name='course_feedback')
    RATING = Choices(1, 2, 3, 4, 5)
    rating = models.CharField(choices=RATING, null=True, max_length=2)

cant we use integers in choices directly ?

1

There are 1 best solutions below

0
user11879807 On

My mistake: rating should be an integer field

rating = models.IntegerField(choices=RATING, null=True, max_length=2)