I'm a beginner with using Python. I have two values that I want to setup if/else logic with. One is the "obj.default_value" and the other is the "obj.override".
The basic summary to my problem is I want to setup an if/else statement that checks if obj.override == 'true' then obj.default_value should change to 'True'. If obj.override == 'false' then obj.default_value should change to 'False'. The final option is if obj.override == 'none' then obj.default_value should stay to the current value it was.
Better yet, if possible I would like the obj.override to negate the value of obj.default_value. True becomes false and vice versa. I want to setup a new function that overrides the default value. I hope I explained all this well and any help would be greatly appreciated.
Here's my current code for two values referenced:
def default_value_custom(self, obj):
color = 'green' if obj.default_value else 'red'
return mark_safe("<span style='color:%s'>%s</span>" % (color, obj.default_value))
default_value_custom.short_description = 'default value'
def override_custom(self, obj):
if obj.override == 'true':
return mark_safe("Always <span style='color:green'>True</span>")
elif obj.override == 'false':
return mark_safe("Always <span style='color:red'>False</span>")
else:
return obj.override