JSONFieldshould callget_prep_value()like all other fields type, because this is the method that thedocumentationtell us to override in custom fields. Otherwise we need to overrideget_db_prep_value()which is heavier and does not have the same purpose. I think simply replacingconnection.ops...
通过覆盖IntegerField和AutoField类,我最终获得了这个自定义错误消息。
TestEnum(enum.Enum):VALUE_1='value_1'classEnumField(models.CharField):defget_prep_value(self,value):ifvalueisNone:returnNoneelse:returnvalue.valueclassTestModel(models.Model):array_of_enums=ArrayField(EnumField(max_length=20))TestModel.objects.filter(array_of_enums__contains=[TestEnum.VALUE_1...