You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Consequently, wq maketemplates renders it as a simple text input which is not a best option.
If these two (Null)BooleanField field types were treated as type "select one", they would hopefully be rendered as choice buttons by wq maketemplates.
The text was updated successfully, but these errors were encountered:
Yes, there isn't an XLSForm equivalent for boolean fields, so a ChoiceField would be the most straightforward alternative. If you want to take a look at this, it could be addressed in ModelSerializer by customizing the field mapping. As a start, you could extend get_fields_for_config():
def get_fields_for_config(self):
fields = self.get_fields()
for name, field in list(fields.items()):
if name == 'id' or field.read_only:
fields.pop(name)
+ elif isinstance(field, serializers.BooleanField):+ fields[name] = serializers.ChoiceField(choices=...)
return fields
This approach is nice because it lets DRF still view the field as a boolean (since get_fields() is unchanged), while generating a useful configuration for use by wq.app and the templates.
However, there is one complication, which is that the default detail templates assume that any field with choices is accompanied with a read-only *_label showing the label for the selected choice. So, you might also want to extend get_label_fields() to generate an equivalent label for boolean fields. The cleanest way to do this is probably to define a custom ReadOnlyField (see LocalDateTimeField for an example).
For such a model
./manage.py dump_config
outputsstring
as the type ofvalid_survey
:Consequently,
wq maketemplates
renders it as a simple text input which is not a best option.If these two (Null)BooleanField field types were treated as type "select one", they would hopefully be rendered as choice buttons by
wq maketemplates
.The text was updated successfully, but these errors were encountered: