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

Set and delete Helper fields by string key #1362

Open
kytta opened this issue Jul 31, 2023 · 0 comments
Open

Set and delete Helper fields by string key #1362

kytta opened this issue Jul 31, 2023 · 0 comments

Comments

@kytta
Copy link

kytta commented Jul 31, 2023

  • Package version: 2.0
  • Django version: 3.2.18
  • Python version: 3.8.17
  • Template pack: crispy-bootstrap5 0.7

Description:

I am conditionally changing the form by adding and removing its fields. I follow the guide to dynamic layouts, but I don't like the indexed addressing because of its WETness: If I add a new field, I'll have to update the indices. There is a way to select a field using its name, but it doesn't work if I want to delete a field.

name_field = self.helper["name"]  # fine
del self.helper["name"]  # TypeError: list indices must be integers or slices, not str

Proposed solution

Extract the key finding logic from DynamicLayoutHandler.__get_item__ and make it available for __del_item__ (and __set_item__, for that matter)

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