1

I'm trying to add additional data to my template named "equipment_form" linked with my view CreateEquipment (CreateView generic django)

So, my model Equipment possess a subcategory. And my model subcategory possess a category.

For UX reasons, I want my user to chose the category of the equipment first, then the subcategory. In order to do this, I need to get in the view the whole content of the category table and give it to the template. And I have some trouble to figure out how I can do it.

I will really appreciate the help of the community! Thank you.

So atm my view look like this :

class EquipmentCreate(CreateView):
   #category list not passed to the template
   category_list = Category.objects.all()
   model = Equipment
   success_url = reverse_lazy('stock:equipment-list')

EDIT : I found the answer here :

Django - CreateView - How to declare variable and use it in templates

Thank you anyway :)

4

1 に答える 1