B
B
blackbb2017-04-09 03:50:50
Django
blackbb, 2017-04-09 03:50:50

Booleanfield and multiple choice?

I'm trying to make a multiple choice on the site in the admin panel using the BooleanField field.
In models.py:

class School(models.Model):
CATEGORY_CHOICES = (
            ('a', 'A'),
            ('a1', 'A1'),
            ('b', 'B'),
            ('b1', 'B1'),
            ('be', 'BE'),
            ('c', 'C'),
            ('c1', 'C1'),
            ('ce', 'CE'),
            ('c1e', 'C1E'),
            ('d', 'D'),
            ('d1', 'D1'),
            ('de', 'DE'),
            ('d1e', 'D1E'),
            ('e', 'E'),
            ('m', 'M'),
            ('tm', 'TM'),
            ('tb', 'TB'),
        )
    category_education = models.BooleanField(choices=CATEGORY_CHOICES, default=False, verbose_name='Категория обучения', blank=True)

In admin.py:
class SchoolAdminForm(forms.ModelForm):
  class Meta:
    model = School
    widgets = {
        
      'category_education': CheckboxSelectMultiple(),

    }
    fields = '__all__'

class SchoolAdmin(admin.ModelAdmin):
  form = SchoolAdminForm
admin.site.register(School, SchoolAdmin)

as a result, the admin panel displays a multiple choice of checkboxes, but when you select any or several and try to save, it says: "Choose the correct option. [u'a1'] (well, or what you chose) is not among the valid values." I can't figure out what's wrong.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question