May 2018
Beginner to intermediate
526 pages
11h 57m
English
After users create an account, they should be able to enroll in courses. In order to store enrollments, we need to create a many-to-many relationship between the Course and User models.
Edit the models.py file of the courses application and add the following field to the Course model:
students = models.ManyToManyField(User, related_name='courses_joined', blank=True)
From the shell, execute the following command to create a migration for this change:
python manage.py makemigrations
You will see an output similar to this:
Migrations for 'courses': courses/migrations/0004_course_students.py - Add field students to course
Then, execute the next command to apply pending migrations:
python manage.py migrate
You should see output ...
Read now
Unlock full access