[Answer]-Processing field input before save with Django

1👍

You could try to do this in your custom widget using the value_from_datadict method. From the Django docstring of this function:

Given a dictionary of data and this widget’s name, returns the value
of this widget. Returns None if it’s not provided.

This method is supposed to return a value based on POST data dictionary and the name of the widget. So in your case you can read your base64 string from POST and convert it into an image file data. This data needs to correspond to what is expected by the ImageField.

This question uses the function I mentioned:
Django subclassing multiwidget – reconstructing date on post using custom multiwidget

Also check the Django code for this function in here:
https://github.com/django/django/blob/master/django/forms/widgets.py

Leave a comment