Django 4.0 - Сохранение нескольких вариантов с помощью поля ManyToManyField

Я пытаюсь сохранить несколько вариантов в моей базе данных

У меня есть примерное представление о том, как это сделать, но я ищу полное решение

Я также хочу, чтобы пользователи могли выбирать несколько вариантов на странице регистрации, поскольку эти значения будут затем сохранены в поле ManyToManyField

Я хочу, чтобы мои пользователи могли получить доступ к блогам для нескольких разделов (в настоящее время я могу заставить это работать только для одного раздела)

Как я могу изменить мой текущий код, чтобы сделать это?

(Это всего лишь мой 3-й вопрос, поэтому любая конструктивная критика будет оценена по достоинству)

models.py

class User(AbstractBaseUser, PermissionsMixin):
    # A full User model with admin-compliant permissions that uses a full-length email field as the username
    # Email and password are required but all other fields are optional
    email = models.EmailField(_('email address'), max_length=254, unique=True)
    username = models.CharField(max_length=50, unique=True)
    first_name = models.CharField(_('first name'), max_length=30, blank=True)
    last_name = models.CharField(_('last name'), max_length=30, blank=True)
    section = models.CharField(max_length=30)
    # section = models.ManyToManyField('UserSection', related_name='sections')
    is_active = models.BooleanField(_('active'), default=True,
        help_text=_('Designates whether this user should be treated as active. Unselect this instead of deleting accounts.'))
    is_staff = models.BooleanField(_('staff status'), default=False,
        help_text=_('Designates whether the user can log into this admin site.'))
    is_executive = models.BooleanField(_('executive status'), default=False, 
        help_text=_('Designates that this user is part of the executive committee.'))
    is_superuser = models.BooleanField(_('superuser status'), default=False, 
        help_text=_('Designates that this user has all permissions without explicitly assigning them.'))
    date_joined = models.DateTimeField(_('date joined'), default=timezone.now)

    objects = UserManager()

    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = ['username']

    class Meta:
        verbose_name = _('user')
        verbose_name_plural = _('users')

    def get_absolute_url(self):
        return "/users/%s/" % urlencode(self.email)

    def get_full_name(self):
        # Returns the first_name plus the last_name, with a space in between
        full_name = '%s %s' % (self.first_name, self.last_name)
        return full_name.strip()

    def get_short_name(self):
        # Returns the short name (first name) for the user
        return self.first_name

    #def email_user(self, subject, message, from_email=None):
        # Sends an email to this User
        #send_mail(subject, message, from_email, [self.email])

"""
class UserSection(models.Model):
    section_name = models.CharField(max_length=30)

    def __str__(self):
        return self.name
"""

views.py

def register(request):
    articles = Article.objects.filter(status=1).order_by('-date_posted')[:2]
    if request.method == 'POST':
        form = UserRegisterForm(request.POST)
        if form.is_valid():
            user = form.save(commit=False)
            user.username = request.POST.get('username')
            user.section = request.POST.get('section')
            user.second_section = request.POST.get('second_section')
            user.save()
            messages.success(request, f'Your account has been created! You are now able to log in')
            return redirect('login')
    else:
        form = UserRegisterForm()
    
    context = {
        'title': 'Register',
        'articles': articles,
        'form': form,
    }

    return render(request, 'accounts/register.html', context)

forms.py

SECTION = [
    ('Beavers', 'Beavers'),
    ('Cubs', 'Cubs'),
    ('Scouts', 'Scouts'),
]

class UserRegisterForm(UserCreationForm):
    email = forms.EmailField()
    section = forms.ChoiceField(label='Childs Section', choices=SECTION, widget=forms.RadioSelect, 
        help_text='Please select the section that your child currently attends.')
    """
    section = forms.MultipleChoiceField(label='Childs Section', choices=SECTION, widget=forms.CheckboxSelectMultiple, 
        help_text='Please select the section(s) that your child currently attends.')
    """
    class Meta:
        model = User
        fields = ['username', 'email', 'first_name', 'last_name', 'password1', 'password2', 'section']

Ниже приведен раздел моего файла base.html, который использует Jinja2 для отображения кнопок для доступа к странице блога каждого раздела

<ul class="navbar-nav ms-auto">
    {% if user.section == 'Beavers' %}
    <li class="nav-item">
        <a class="nav-link" href="{% url 'beavers_blog_home' %}"><span class="fas fa-blog"></span> Beavers Blog</a>
    </li>
    {% endif %}
    {% if user.section == 'Cubs' %}
    <li class="nav-item">
        <a class="nav-link" href="{% url 'cubs_blog_home' %}"><span class="fas fa-blog"></span> Cubs Blog</a>
    </li>
    {% endif %}
    {% if user.section == 'Scouts' %}
    <li class="nav-item">
        <a class="nav-link" href="{% url 'scouts_blog_home' %}"><span class="fas fa-blog"></span> Scouts Blog</a>
    </li>
    {% endif %}
    {% if user.is_authenticated %}
    <li class="nav-item">
        <a class="nav-link" href="{% url 'profile' %}"><span class="fas fa-users"></span> Profile</a>
    </li>
    <li class="nav-item">
        <a class="nav-link" href="{% url 'logout' %}"><span class="fas fa-sign-out-alt"></span> Logout</a>
    </li>
    {% else %}
    <li class="nav-item">
        <a class="nav-link" href="{% url 'login' %}"><span class="fas fa-sign-in-alt"></span> Login</a>
    </li>
    <li class="nav-item">
        <a class="nav-link" href="{% url 'register' %}"><span class="fas fa-user-plus"></span> Register</a>
    </li>
    {% endif %}
</ul>
Вернуться на верх