1👍
✅
You can override DetailView’s get_context_data
to add RoletoFunction
model’s data to context. For example:
class FunctionDetail(DetailView):
...
def get_context_data(self, **kwargs):
context = super(FunctionDetail, self).get_context_data(**kwargs)
if 'function_id' in kwargs: #this is how you can get function_id's data from url
_id = int(kwargs['function_id'] or '0')
else:
_id = 0
function = Function.objects.get(id=_id)
context['role_function'] = RoletoFunction.objects.filter(function=function)
return context
Source:stackexchange.com