慕标5832272
弄清楚了!我__init__像这样覆盖了模型的方法:class MyModel(models.Model): def __init__(self, *args, **kwargs): # Don't do any extra looping or anything in here because this gets called # at least once for every row in each query of this table self._meta.fields[2].model_instance = self super(MyModel, self).__init__(*args, **kwargs) field1 = models.TextField() field2 = models.PickleField() field3 = models.DateTimeField()然后在我的字段子类中:def to_python(self, value): # logic and unpickling, then right before your return: if hasattr(self, 'model_instance'): # avoid AttributeError if list, dict, etc. value.model_instance = self.model_instance return value