Closed aidanlister closed 10 years ago
You just need to refer to the .nested
formset to get the nested media. I've updated the BaseNestedFormset
class to do this as a convenience.
Hrm I can't get this working.
from nested_formset import nestedformset_factory
from django.forms.models import inlineformset_factory
from abas.apps.contractors.forms import *
nf_class = nestedformset_factory(
Signoff,
SignoffProperty,
inlineformset_factory(
SignoffProperty,
SignoffItem,
form=SignoffItemForm,
can_delete=False,
extra=0,
fields=('last_service_date', 'signoff_note', 'is_compliant'),
),
form=SignoffPropertyForm,
extra=0,
can_delete=False,
fields=('note', 'is_disclaimed'),
)
nf = nf_class(Signoff.objects.get(pk=1))
str(nf.media)
>>> ''
str(nf.forms[0].nested.forms[0].media)
>>> '<link href="/static/libraries/bootstrap-datepicker/css/datepicker3.css" type="text/css" media="screen" rel="stylesheet" />
#check for right version
import nested_formset
nested_formset.BaseNestedFormset.media
<property object at 0x105c3baf8>
Note to anyone who needs an immediate fix, you can use: {{ form.forms.0.nested.forms.0.media }}
It's not sufficient to just check for the presence of media
to make sure you have the newest version: BaseNestedFormset
had a media
property before, which it inherits from the BaseInlineFormSet
.
If you look at the test_properties.py
file (https://github.com/nyergler/nested-formset/blob/master/src/nested_formset/tests/test_properties.py), do you see anything obviously different between your form declarations and those in the test case?
Hey nyergler, ah yes, my Media is meant to come from the individual widgets Media's, rather than something I have added directly onto the formset.
I just added another test case to test_properties.py
to test that media from widgets on the grandchild forms is rolled up correctly, and it passes.
Can you tell me how you upgraded to the latest master? Based on what you're seeing, it really sounds like you're still using the old version.
Ahh I must have specified the wrong commit in my requirements.txt, it's working as expected. Thanks!
Ah, great, glad we figured it out!
I went ahead and made an 0.1.2 release on PyPI so it's a little easier to get the improved version.
Thanks again for the suggestion!
I can't work out a way to grab the form.media from the grandchild form ... is there a way we can make the master formset collect media for the the child and grandchild forms?