django-unicorn
django-unicorn copied to clipboard
Class Based View not supported for nesting
When I want to carry out the example of the table doing searches but with a class-based view (templateview), I got the error: 'AttributeError: 'SampleView' object has no attribute 'component_id'
Looking through the template variables, I noticed that the class-based view is overwriting the view variable.
When I made the view with a function, this was the data obtained in the table view:
'view': <unicorn.components.table.TableView object at 0x0000021ACDBED990>}
When I made the class, I got the error mentioned and the following in the variable:
'view': <basket.views.SampleView object at 0x000001E71DEF2920>}
It is worth mentioning that the unicorn component without nesting works without problem
Thank you very much and hopefully it's just my mistake
Can you fork this repo and make an example of how you are creating the view. Thank you!
Same thing is happening to me. It's my first time trying to implement a nested component and I can't get it to work.
In order to access self.parent in the child component, I include it as {% unicorn 'my-child-component' parent=view %} inside my unicorn parent component. As soon as doing that an error occurs "AttributeError: ' object has no attribute 'component_id'"
ProductDetailView is the CBV TemplateView where I include the main unicorn component as {% unicorn 'my-parent-component' %}.
I tried printing {{ view }} in the parent component template to see if it was including its view (as it should be) and everything seems to be working there. The problem I can't solve is why when setting parent=view when I include the child component, my parent component now thinks it has a parent (when it DOESN'T). At least that's what I think is happening.
Thanks a lot for the help !
I think I figured out what was going on with TemplateViews in https://github.com/adamghill/django-unicorn/pull/430. I'm still trying to figure out if #428 is also needed or not. I'll make a release soon and let you know.
This should be fixed in 0.46.0. I'm going to close this issue, so please try it out and let me know if you run into other problems.
I had a similar issue as I get 'str' object has no attribute 'component_id', I didn't have any view variable at all in the component template. I succeeded to fix it, I was overriding get_context_data to get data from database and display it in my view, but it was disabling the view variable. Not sure if it's a normal behavior or not.