segun Oregunwa
segun Oregunwa

Reputation: 45

How to use Multi Choice Field in Django 2.0

This picture below illustrate all what I want to implement in the Database. Please I don't know how to connect the Unit and Course_code fields in the model with each course in the choice field.... Students can enroll all Courses in the Turple model.pyMultiChoiceField

class Course(models.Model):
    COURSES_CHOICES = (
        ('analysis', 'Analysis'),
        ('numerical', 'Numerical'),
        ('philosophy', 'Philosophy'),
    )

    course_names = models.Charfield(choices=COURSES_CHOICES, null=True,)
    course_code = models.CharField(max_length=40)
    couse_unit = models.intergerField()

class Department(models.Model):
    name = models.Charfield(max_length=30)
    student = models.ForeignKey(User)
    course = models.ManyToManyField(Course)

I dont know if am right with my model.py... Am still a learner in Django

Upvotes: 1

Views: 605

Answers (1)

Xhens
Xhens

Reputation: 802

I think this might solve what you want to do.

class Department(models.Model):
    name = models.Charfield(max_length=30)
    student = models.ForeignKey(User)
    course = models.ForeignKey(
        to='Course',
        on_delete=models.CASCADE,
    )

Upvotes: 1

Related Questions