Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to pass an initial value to an imagefield in a django form

Currently I am using something like:

initialValues={
    'textField1':'value for text field 1',
    'textField2':'value for text field 2',
    'imageField': someModel.objects.get(id=someId).logo
    }

form = myForm(initial=initialValues)

When I call myForm as above, the initial values are displayed as expected: the textField1, textField2 and imageField (with the options Currently: linkToImage, Clear check box and Change: )

But when I save the form, there is nothing saved in the imageField field (checking the database and I see the imageField field blank).

I know that I miss something here, but I cannot figure out what. Any tips?

like image 946
marlboro Avatar asked Sep 10 '25 15:09

marlboro


1 Answers

I solved my issue by assigning

request.FILES['imageField']=someModel.objects.get(id=someId).logo

just before I save the form. Yeey

like image 149
marlboro Avatar answered Sep 13 '25 05:09

marlboro