How can you know if a value is the default value for a Model’s property.
For example
class Alias(models.Model) :
image = models.ImageField(upload_to='alias', default='/media/alias-default.png')
a = Alias.get("123")
# this doesn't work
if a.image == a.image.default :
pass
# nor this
if a.image == Alias.image.default :
pass
I tried digging in the docs, but didn’t see anything.
The
defaultin Django is not the same as SQL default – it’s there merely for admin to auto-fill the form field on new object creation.If you want to compare something to value defined as
defaultyou have to define it somewhere else (i.e. insettings.py). Like:The
defaultvalue is stored inMyModel._meta._fields()[field_creation_index].defaultbut be aware that this is digging in internals.