Hello!
I have used Django FilteredSelectMultiple widget in my project - very nice widget, havent found anything similar to this for my app - selecting and ordering lab tests.
But i have a question - is it even possible to enable OPTGROUPs for the SELECT in the widget when using ModelForm? Or is it just list plainly all select options without optgroups?
For example - i have 2 models:
class ProbeGroup(models.Model):
name = models.CharField("Название Группы", max_length=200, blank=True, null=True)
description = models.CharField("Описание", max_length=200, blank=True, null=True)
id = models.UUIDField("Идентификатор", default=uuid.uuid4, unique=True, primary_key=True, editable=False)
order = models.IntegerField("Порядок", default=1)
def __str__(self):
return str(self.name)
class Probe(models.Model):
name = models.CharField("Название теста", max_length=200, blank=True, null=True)
description = models.CharField("Описание", max_length=200, blank=True, null=True)
id = models.AutoField("Идентификатор", primary_key=True)
order = models.IntegerField("Порядок", default=1)
enabled = models.BooleanField("Включен для клиента", default=True)
related_to_probegroup = models.ForeignKey(ProbeGroup, on_delete=models.CASCADE, null=True, blank=True,
verbose_name="Привязка к группе")
probeSpecial = models.CharField("Спец.маркер", max_length=250, blank=True, null=True)
code = models.CharField("Код", max_length=200, blank=True, null=True)
And want the widget to show both Probes as select option and Probegroups as optgroups, is it possible?
I am using the widget as follow:
class CreateOrderForm(ModelForm):
class Meta:
model = Zakaz
fields = '__all__'
widgets = {
'patient': autocomplete.ModelSelect2(url='country-autocomplete', attrs={'data-theme': 'bootstrap4'}),
'probe': FilteredSelectMultiple(u'Анализы', False,),
}