Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with the include argument #12

Open
MichaelOC05 opened this issue Jan 17, 2024 · 0 comments
Open

Issue with the include argument #12

MichaelOC05 opened this issue Jan 17, 2024 · 0 comments

Comments

@MichaelOC05
Copy link

MichaelOC05 commented Jan 17, 2024

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."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant