nyergler / nested-formset

Nest Django formsets for multi-level editing.
BSD 3-Clause "New" or "Revised" License
87 stars 21 forks source link

NameError with NestedFormSet #30

Closed hboyco closed 6 years ago

hboyco commented 6 years ago

I've been trying to implement the nested formsets code for creating timestamped database entries that can be updated, but I keep running into an issue with the init.py code where I can't import the nestedformset_factory into my view file. Each time I run my server to see what pops up, I get a NameError in my view, with NestedFormSet being undefined. My views.py and init.py files are in different subdirectories of the same directory for organizational purposes.

hboyco commented 6 years ago

A related question, possibly rewording the former, would be how to initialize the formset in views and in a template.

nyergler commented 6 years ago

It's not clear to me if this is an issue with the library or with the way you've laid your project out (your comment about __init__.py and views.py being in different subdirectories makes me wonder if it's a project issue). What version of Django are you using? What version of Python? (Note that I haven't tested this with Django 2 at all, so it's very possible it's incompatible.)

If you can provide a simple example that demonstrates the issue, that's going to help a lot with debugging.

hboyco commented 6 years ago

I'm working with Django 1.9 and Python 3.

The files are organized into my directory as follows: main_dir/assets_dir/views.py main_dir/assets_dir/models.py main_dir/assets_dir/templates/status.html main_dir/assets_dir/nested_formset_dir/__init__.py

Among the differences between versions 1.3 and 1.9 of Django, I noticed that a nested formset was no longer initialized at the start of __init__.py, before class BaseNestedFormset, so I'm not sure how I can initialize my nested formset in views.py without a NameError.

nyergler commented 6 years ago

I've just updated the demo application to work with Django 1.11. Note that you need to use the nested_formset_factory to generate your class.

Hope that helps.

hboyco commented 6 years ago

Thanks for the update. The issue has been resolved.

Also, thanks for sharing the code. It has been serious help.