Skip to content
Advertisement

problems with get_context_data in ListView (django)

I need to show in a template two models:

models.py:

JavaScript

and created a ListView of this

views.py

JavaScript

I need to created a filter of the same ‘dimension’ so that in the template show only the subdimensions of that dimension.

my template dimension.html:

JavaScript

but if u notice, show all the subdimensiones in all cards, not only the subdimension of these dimension.

Manager.py only returns a objects with filter active=True and order_by(‘sort_order’)

Advertisement

Answer

You can do it with inefficient rendering, but if you have 100-200 subdimensions – it should not be a problem.

JavaScript

Alternatively, you can annotate all dimensions with corresponding subdimensions in the view.

JavaScript

and then in template

JavaScript

(… or switch to Jinja2 template rendering to access dimension.subdimension_set.all() directly in template)

Also you can have a look at LoginRequiredMixin instead of method_decorator(login_required)

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement