Search code examples
sqldjangopostgresqlfilefield

Django ImageFieldFile set to <ImageFieldFile: null>. How to change it to blank/empty, like other entries in the table?


I have a FileField in a Django Model. Some entries in this FileField are set to <ImageFieldFile: null>. The rest of the Model table are blank or actual images. I need to clean this table so that these erroraneous entries are also changed to blank, as this is not acceptable in my DRF API.


Solution

  • Get all the image instance.

    objs =myclassmodel.objects.all() //just assuming this
    for obj in objs:
        obj.image = ""
        obj.save()
    

    It will you if understand it right.