diff --git a/datatableview/templates/datatableview/bootstrap_structure.html b/datatableview/templates/datatableview/bootstrap_structure.html index 232a7e32..dc912c1e 100644 --- a/datatableview/templates/datatableview/bootstrap_structure.html +++ b/datatableview/templates/datatableview/bootstrap_structure.html @@ -1,3 +1,24 @@ + + + + + {% for column in datatable %} - + {% endfor %} diff --git a/datatableview/utils.py b/datatableview/utils.py index 48dd514b..4dcebc22 100644 --- a/datatableview/utils.py +++ b/datatableview/utils.py @@ -42,7 +42,7 @@ "PositiveSmallIntegerField": "number", "SlugField": "text", "SmallIntegerField": "number", - "TextField": "text", + "TextField": "textarea", "TimeField": "text", "ForeignKey": "select", } diff --git a/datatableview/views/xeditable.py b/datatableview/views/xeditable.py index 277215b8..1256d836 100644 --- a/datatableview/views/xeditable.py +++ b/datatableview/views/xeditable.py @@ -174,7 +174,18 @@ def _get_foreignkey_choices(self, field, field_name): # will consequently try to assume initial=None, forcing the blank option to appear. formfield_kwargs["empty_label"] = None formfield = field.formfield(**formfield_kwargs) - return formfield.choices + + # In case of using Foreignkey limit_choices_to, django prepares model form and handles + # form validation correctly, so does django-datatableview with x-editable plugin. However + # this piece of code helps filtering limited choices to be only visible choices,else + # all the choices are visible. + if formfield.limit_choices_to: + formfield.queryset = formfield.queryset.filter(**formfield.limit_choices_to) + + # return formfield.choices + # formfield choices deconstructed to get ModelChoiceIteratorValue correctly (>= Django 3.1) + # https://docs.djangoproject.com/en/3.2/ref/forms/fields/#django.forms.ModelChoiceIteratorValue.value + return [(i[0].__str__(), i[1]) for i in formfield.choices] def _get_default_choices(self, field, field_name): return field.choices
{{ column.label }}{{ column.label }}