'Django-How can I upload image to a Model, without that field being present in the ModelForm

I am trying to build an image steganography application and for the encoding part I have a form with two fields, one for image and one for the message that is to be encoded. The encoding part takes place in views.py, but I do not seem to manage how to upload the encoded image in the ImageModel in order to use it later for the decoding part.

1. If I include image_e in the form as a hidden field, I get an error that it needs to be submitted

2. If somehow the form is being submitted, the model contains only the two fields present in the form, 'image' and 'message', and for 'image_e' i get None or the default if i have that option

3. Right now, if I fill the form I get the defaults for the image fields, but not for the char one

I actually only need 'image_e' stored, but I thought that if I inherit all of the fields from the model it would be easier. I am a beginner in Django and this is my first more complex application.

models.py

class Image(models.Model):
image = models.ImageField(upload_to='images', default='default.png')
message = models.CharField(max_length=200, default=1)
image_e= models.ImageField(upload_to='encoded', blank=True)

forms.py

class EncodeForm(forms.ModelForm):
#method= forms.CharField(label='How would you like to encode this image?', widget=forms.Select(choices=METHOD_CHOICES))
"""Form for the image model"""
class Meta:
    model = Image
    fields=('image', 'message', 'image_e')


def encode(self):
    pass

views.py

def image_upload_view(request):
"""Process images uploaded by users"""
if request.method == 'POST':
    
    form = EncodeForm(request.POST, request.FILES)
    #form.fields['image'].save(im.name, im, save=True)
    #form.fields['image_e'].save(image_e.name, image_e, save=True)
    
    if form.is_valid():    
        msg=request.POST.get('message')
        im=request.FILES.get('image')
        image_e=encryptImage(im,msg)
        data={
        'image':im,
        'message':msg,
        'image_e':image_e
        }
        form=EncodeForm(data)
        #Image.objects.create(**data)
        img_obj = form.instance
        form.save()


        return render(request, 'img_steg/encode.html', {'form': form,'img_obj':img_obj})
else:
    form = EncodeForm()
return render(request, 'img_steg/encode.html', {'form': form})

This is how ImageModel looks from the admin view if i submit the form

Edit: This is what the data dictionary contains: {'image': <InMemoryUploadedFile: landscape_0.jpg (image/jpeg)>, 'message': 'ttttt', 'image_e': <InMemoryUploadedFile: im_enc_cfc97e92-b2ef-421d-a108-89f3948ce1ab (image/jpeg)> }



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source