#29488: FilteredSelectMultiple Controls Don't Work if The Name of the Widget
Has a
Space
-------------------------------------+-------------------------------------
Reporter: Mark Phillips | Owner: nobody
Type: Bug | Status: closed
Component: contrib.admin | Version: 2.0
Severity: Normal | Resolution:
| worksforme
Keywords: | Triage Stage:
FilteredSelectMultiple widget | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Mark Phillips):
Tim,
After looking at your example, I see I did a bad job of explaining the
bug. In my program, I create the fields for the adminForm on the fly
because the fields are not defined until run time. I have these lines of
code:
{{{
class MetaDataNames(models.Model):
meta_name_id = models.AutoField(primary_key = True)
name = models.CharField(max_length=200, unique=True)
class MetaDataValues(models.Model):
meta_value_id = models.AutoField(primary_key = True)
meta_name_id = models.ForeignKey(MetaDataNames,
on_delete=models.CASCADE,)
value = models.CharField(max_length=200, unique=True)
class Document(models.Model):
test_id = models.AutoField(primary_key = True)
doc_name = models.CharField(max_length=200, unique=True)
metadata = jsonfield.JSONField(blank=True)
This lines of code in the DocumentAdminForm(forms.ModelForm) contains :
def __init__(self, *args, **kwargs):
metadata_names = MetaDataNames.objects.all()
# create the fields
for metadata in metadata_names:
self.fields[metadata.name] =
forms.ModelMultipleChoiceField(widget=FilteredSelectMultiple(metadata.name,
is_stacked=False), required=False,
queryset=MetaDataValues.objects.filter(meta_name_id=metadata.meta_name_id).order_by('value'),)
.....
}}}
The issue with the FilteredSelectMultiple widget is that when the field
name has a space, the controls don't work. In the code above, where it
says self.fields[metadata.name], the metadata.name part is the string 'Pet
Names', with a space. If I use 'Pet_Names', then the controls in the
widget work.
I may be offending the Django Gods by having a field name with a space in
it. One cannot do that in a model, as far as I can figure out. However, it
is an interesting edge case for the widget, since it is perfectly
reasonable for one to create fields as I am doing.
I can continue to create the test case based on the above code if you
want. However, if the answer is that I cannot have a field name with a
space, then I won't bother.
Please let me know if I should continue with a full test case, or that
nothing will be done because I have a field name with a space in it.
Thanks,
Mark
--
Ticket URL: <https://code.djangoproject.com/ticket/29488#comment:12>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/064.d57d13305076326f5a079eb9b4f2202b%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.