django-forms-dynamic icon indicating copy to clipboard operation
django-forms-dynamic copied to clipboard

Issue with the include argument

Open MichaelOC05 opened this issue 1 year ago • 0 comments

Following the documentation for the car make/model example with an addition of using the include argument results in an error.

Not sure if I am mistaken in my understanding of the include keyword. My understanding is that if it evaluates to True then the field is shown, if it evaluates to False the field is not shown. When using the keyword include the below exception occurs.

I have tried this with two setups:

  • using Django 4.2 and Python 3.10.11 and using Django 5 and python 3.11.7

The code is the exact same as the code in the documentation except that the in the model DynamicField include=lambda form: form["make"].value() == "audi" is added.

The below expection occurs when a make other than audi is selected from the dropdown.

Exception File "D:\mikem\projects\django-forms-dynamic-walkthrough\django-htmx-chained-dropdown.venv310\lib\site-packages\django\forms\forms.py", line 178, in getitem field = self.fields[name] KeyError: 'model'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "D:\mikem\projects\django-forms-dynamic-walkthrough\django-htmx-chained-dropdown.venv310\lib\site-packages\django\core\handlers\exception.py", line 55, in inner response = get_response(request) File "D:\mikem\projects\django-forms-dynamic-walkthrough\django-htmx-chained-dropdown.venv310\lib\site-packages\django\core\handlers\base.py", line 197, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "D:\mikem\projects\django-forms-dynamic-walkthrough\django-htmx-chained-dropdown\core\views.py", line 61, in htmx_models return HttpResponse(form["model"]) File "D:\mikem\projects\django-forms-dynamic-walkthrough\django-htmx-chained-dropdown.venv310\lib\site-packages\django\forms\forms.py", line 180, in getitem raise KeyError( KeyError: "Key 'model' not found in 'MakeAndModelForm'. Choices are: make."

MichaelOC05 avatar Jan 17 '24 14:01 MichaelOC05