美文网首页
Django ContentType

Django ContentType

作者: whenitsallover | 来源:发表于2018-02-27 19:30 被阅读0次

Official link

https://docs.djangoproject.com/en/2.0/ref/contrib/contenttypes/#django.contrib.contenttypes.fields.GenericForeignKey

Generic relations

There are three parts to setting up a GenericForeignKey:

  1. Give your model a ForeignKey to ContentType. The usual name for this field is 'content_type'.
  2. Give your model a field that can store primary key values from the models you'll be relating to. For most models, this means a PositiveIntegerField. The usual name for this field is 'object_id'.
  3. Give your model a GenericForeignKey, and pass it the names of the two fields described above. If these fields are named 'content_type' and 'object_id', you can omit this - those are the default field names GenericForeignKey will look for.

相关文章

网友评论

      本文标题:Django ContentType

      本文链接:https://www.haomeiwen.com/subject/yggmxftx.html