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

form_kwargs and get_form_kwargs for inline forms missing #256

Open
dw-liedji opened this issue Dec 29, 2022 · 1 comment
Open

form_kwargs and get_form_kwargs for inline forms missing #256

dw-liedji opened this issue Dec 29, 2022 · 1 comment

Comments

@dw-liedji
Copy link

Hello everyone.

Please, which parameter or method should one use if one wants to add parameter to inline forms at runtime or not. I have tried to use the formset_kwargs and setting the form_kwargs attribute of the formset_kwargs dictionary as shown in this section of the django-extra-views docs but it was not working as expected. I obtained the following error:

Exception Type: KeyError at /creditium/inventories/product-types/add/
Exception Value: 'form_kwargs'

Here is the full traceback:

Environment:

Request Method: GET
Request URL: http://127.0.0.1:8000/creditium/inventories/product-types/add/

Django Version: 4.1.4
Python Version: 3.8.8

Traceback (most recent call last):
  File "/home/liedji/.local/share/virtualenvs/quanta-Yd3H_Mzp/lib/python3.8/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
  File "/home/liedji/.local/share/virtualenvs/quanta-Yd3H_Mzp/lib/python3.8/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/liedji/.local/share/virtualenvs/quanta-Yd3H_Mzp/lib/python3.8/site-packages/django/views/generic/base.py", line 103, in view
    return self.dispatch(request, *args, **kwargs)
  File "/home/liedji/.local/share/virtualenvs/quanta-Yd3H_Mzp/lib/python3.8/site-packages/django/views/generic/base.py", line 142, in dispatch
    return handler(request, *args, **kwargs)
  File "/home/liedji/.local/share/virtualenvs/quanta-Yd3H_Mzp/lib/python3.8/site-packages/extra_views/advanced.py", line 137, in get
    return super().get(request, *args, **kwargs)
  File "/home/liedji/.local/share/virtualenvs/quanta-Yd3H_Mzp/lib/python3.8/site-packages/extra_views/advanced.py", line 95, in get
    inlines = self.construct_inlines()
  File "/home/liedji/.local/share/virtualenvs/quanta-Yd3H_Mzp/lib/python3.8/site-packages/extra_views/advanced.py", line 79, in construct_inlines
    inline_formset = inline_instance.construct_formset()
  File "/home/liedji/.local/share/virtualenvs/quanta-Yd3H_Mzp/lib/python3.8/site-packages/extra_views/advanced.py", line 31, in construct_formset
    formset = super().construct_formset()
  File "/home/liedji/.local/share/virtualenvs/quanta-Yd3H_Mzp/lib/python3.8/site-packages/extra_views/formsets.py", line 38, in construct_formset
    return formset_class(**self.get_formset_kwargs())
  File "/home/liedji/liedji/djangoro/quanta/apps/inventories/views.py", line 315, in get_formset_kwargs
    kwargs["form_kwargs"].update({"initial": {"organization": 1}})

Exception Type: KeyError at /creditium/inventories/product-types/add/
Exception Value: 'form_kwargs'

So, can we fix this to allow passing parameter to inline forms ? In addition, having a simple interface called form_kwargs et get_form_kwargs for inline forms for doing that will be more easier and more consistent for passing parameters of inline forms at runtime or not.

@yedpodtrzitko
Copy link

hi,
can you show your code? Most likely you're doing something unexpected there.

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

2 participants