Django ContentType

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)