Skip to content Skip to sidebar Skip to footer

How To Change Another Field Value When Clear In Django?

I am working with Django form Updation, but I am facing a small issue, I have 3 fields in form updating, name, image, status, Now if a user uploads an image in the form then the st

Solution 1:

When you run the code by unchecking the checkbox, the following line will be skipped:

if instance.image:
    instance.status = 1# This will be skipped since instance.image is now False

Try adding an action for when the condition for instance.image is false.

if instance.image:
    instance.status = 1else:
    instance.status = 0

You can of course refactor that to write it more elegantly but that clearly shows the logic.

Post a Comment for "How To Change Another Field Value When Clear In Django?"