I have a function that process images that are uploaded by users. I made a view that when entered apply the function on the uploaded images.
models.py
class UploadedImages(models.Model):
patient = models.ForeignKey(Patient,on_delete=models.CASCADE,related_name='images')
pre_analysed = models.FileField(upload_to = user_directory_path ,
verbose_name = 'Image')
class Processed(models.Model):
uploaded_image = models.ForeignKey(UploadedImages,on_delete=models.CASCADE,related_name='processed')
analysedimage = models.ImageField(upload_to=analyses_directory_path,
verbose_name='analysed Image', blank=True)
views.py
def AnalysedDetails(request,pk=None):
Uimage = get_object_or_404(models.UploadedImages,pk=pk)
analysed = models.Processed(uploaded_image=Uimage,analysedimage=main(Uimage.pre_analysed.path))
analysed.save()
return HttpResponse("OK")
but when i check the admin page to see the model it only saves the uploaded image and doesn't save the processed one and when I check the directory i find that only the uploaded image field is saved.
I tried
analysed=models.Processed(uploaded_image=Uimage.pre_analysed,analysedimage=main(Uimage.pre_analysed.path))
but it returns
Cannot assign "": "Processed.uploaded_image" must be a "UploadedImages" instance