class MyModel(models.Model):
…other fields…
content_type = models.ForeignKey(ContentType, blank=True, null=True, on_delete=models.SET_NULL)
object_id = models.PositiveIntegerField(blank=True, null=True)
content_object = generic.GenericForeignKey(‘content_type’, ‘object_id’)
django orm里面的 content_type
本文介绍了在Django框架中,如何使用GenericForeignKey实现模型之间的关联,包括ForeignKey引用ContentType和PositiveIntegerField关联对象实例。
摘要由CSDN通过智能技术生成