Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

522
Visualizações
Django CheckboxSelectMultiple() widget - Form widget value not selected after saving data options

How to can I work with multiple select options and make these options selected to stay selected ?

Some application? Should I use any JS?

Is possible that my approach may be incomplete or miss something ...?

Context

I have the following model:

class AcademicPeople(models.Model):

    CATHEDRAL_PROFESSOR = 'CATHEDRAL'
    RESEARCH_PROFESSOR = 'RESEARCH'
    INSTITUTIONAL_DIRECTIVE = 'DIRECTIVE'

    OCCUPATION_CHOICES = (
        (CATHEDRAL_PROFESSOR, 'Cathedral Professor'),
        (RESEARCH_PROFESSOR, 'Research Professor'),
        (INSTITUTIONAL_DIRECTIVE, 'Institutional Directive'),
    )

    occupation = models.CharField(
        max_length=255,
        blank = False,
    )

In the forms.py I have:

from .models import
from django.forms.widgets import CheckboxSelectMultiple

class AcademicPeopleForm(forms.ModelForm):
    title = "Details"
    occupation = forms.MultipleChoiceField(
        required=False,
        label='Occupation',
        widget=CheckboxSelectMultiple(),
        choices=AcademicPeople.OCCUPATION_CHOICES
    )

    class Meta:
        model = AcademicPeople
        fields = ('occupation',)

UPDATE

My view is very basic, is the following:

class AccountSettingsUpdateView(LoginRequiredMixin, UpdateView):
    model = AcademicPeople
    form_class = AcademicPeopleForm
    success_url = reverse_lazy('dashboard')
    context_object_name = 'preferences'

When I go to my template using the browser, I get the checkbox select multiple rendered in checkboxes, I select some options and when I save, these options selected does not show their value.

enter image description here

about 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda