[Python] Can't add a field with an election

Discussão em 'Python' iniciado por Stack, Abril 16, 2025.

  1. Stack

    Stack Membro Participativo

    models.py:

    from django.db import models


    class Teacher(models.Model):
    MATH = 'MT'
    PHYS = 'PH'
    COMP = 'CS'
    SUBJECTS_TEACHER_CHOICES = {
    MATH: 'Math',
    PHYS: 'Phys',
    COMP: 'Comp',
    }
    subjects = models.CharField(
    max_length=2,
    choices=SUBJECTS_TEACHER_CHOICES,
    default=MATH,
    )
    first_name = models.CharField(max_length=128)


    error: ERRORS:
    TeachersApp.Teacher.subjects: (fields.E005) 'choices' must be an iterable containing (actual value, human readable name) tuples.


    I want to add a field with choices.

    Continue reading...

Compartilhe esta Página