I'm handling some edge cases in some django code, and i'm hitting a problem that is only encountered when specific fields are involved.
I want to be able to detect the class that the Model is using for a field and depending upon the result drop into alternate logic.
I've tried to use get_internal_type()
on the field instance but it just returns "BooleanField"
and not the expected "ModifiedField"
The Custom Field Type:
class ModifiedField(models.BooleanField):
def __init__(self, *args, **kwargs):
kwargs['editable'] = False
models.BooleanField.__init__(self, *args, **kwargs)
def pre_save(self, model_instance, add):
value = getattr(model_instance, self.attname)
if add:
return True
elif value == 2:
return False
else:
return True
Model:
class TemplateItem(models.Model):
uuid = UUIDField(primary_key=True)
name = models.CharField(null=False, blank=True, max_length=255)
image = models.ImageField(_('Image'), upload_to=_template_image_upload_path,
storage=item_fs, null=True, blank=True)
is_modified = ModifiedField()