[Fixed]-How is value for content_type_id generated in generic foreign key?

1👍

It’s a foreign key to the ContentTypes table.

0👍

The number is assigned by the contentype framework. You can take a look at this by adding this to your admin.

Add these lines in any of your apps admin.py file:

from django.contrib.contenttypes.models import ContentType
class CTAdmin(admin.ModelAdmin):
    list_display=('app_label','model', 'id')
admin.site.register(ContentType, CTAdmin) 

Then you’ll see a Contenttype app in your admin and this will show a list of all models and ids.

Leave a comment