How would I pass the request.user object into the render function of a custom widget I have created, or what is the best way to access the current user from within the render function
Solution I believe is not yet a hack (but close to) and is not that big hassle.
Override init on your forms:
def __init__(self, *args, **kwargs):
user = kwargs.pop('user', None)
super(SomeForm, self).__init__(*args, **kwargs)
self.fields['your_field'].widget.user = user
Override your widget:
def __init__(self, *args, **kwargs):
self.user = None
super(YourWidget, self).__init__(*args, **kwargs)
Make profit with your user on a widget.
Obviously you need provide user to a form, and this on some edge cases might be a problem, for example you are using django dynamic views and you hate to change them to somewhat more static approach.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With