Open joshuadavidthomas opened 1 month ago
Hi @joshuadavidthomas. Thanks for the report.
Let me first acknowledge the issue. Yes, something here would be good.
Then your method should probably not return an Optional, but rather an empty dictionary where it currently returns None. That would simplify the call sites it seems.
I'm going to ask you to stick with this for the moment.
I'm working through several related thoughts to do with roles, and customisation, and I won't have a better answer for you until that falls out. Until then adding the hook as you've done is perfectly fine.
Recently I have found myself working on a
CRUDView
for a complex model with relationships to a bunch of ancillary models. Theget_context_data
method has started to become a bit overstuffed with variables I only ever need for one role or another.It would be nice if the view offered something for role specific contexts, similar to
get_FOO_display
for model choices.After playing around a bit, I quite like where I landed in my
CRUDView
subclass:This allows for defining role specific context data functions, e.g.
get_create_context_data
- key line beingrole_context = func(context=context, **kwargs)
. They need to be defined with**kwargs
and return adict
as I have it now, but you could probably even do away with the kwargs requirement somehow if desired.