我在一个项目中完成了与方法2类似的操作:
from django.db import modelsfrom django.contrib.contenttypes.models import ContentTypeclass baseModel(models.Model): type = models.ForeignKey(ContentType,editable=False) # other base fields here def save(self,force_insert=False,force_update=False): if self.type_id is None: self.type = ContentType.objects.get_for_model(self.__class__) super(baseModel,self).save(force_insert,force_update) def get_instance(self): return self.type.get_object_for_this_type(id=self.id)



