How and when to use GenericForeignKey?
Let’s first understand the meaning of generic, according to the oxford dictionary generic means;
shared by, including, or typical of a whole group of things; not specific
So, as you can see the meaning states clearly that it is not specific to anything. That means GenericForeignKey is not specific to one model rather it can have a relation between any model in your Django application. If you have been a Rails developer, you would be familiar with Polymorphic Associations. So in Django, it’s pretty much the same as the Polymorphic Associations in Rails.
If you are going to use GenericForeignKey in your current project, make sure you have a contenttypes framework in your INSTALLED_APPS settings because GenericForeignKey depends on it.
date:Nov. 9, 2025