Opened 14 years ago
Closed 5 years ago
#14408 closed Bug (invalid)
Admin Error when subclassing ContentType for generic Relations
Reported by: | MS | Owned by: | nobody |
---|---|---|---|
Component: | contrib.admin | Version: | 1.2 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
If you subclass the ContentType with a proxy model, for example to use other ordering or change some other Meta options, you will get an error in the Admin interface, when using GenericTabularInline.
The problem is line 357 in http://code.djangoproject.com/browser/django/trunk/django/contrib/contenttypes/generic.py, where the test is with equal but should be subcalss instead.
Example in models:
from django.db import models from django.contrib.contenttypes import generic from django.contrib.contenttypes.models import ContentType as CT class ContentType(CT): class Meta: proxy = True ordering = ('app_label', 'model') class ModelWithGeneric(models.Model): content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() contentObject = generic.GenericForeignKey('content_type', 'object_id') class ObjectWithGeneric(models.Model): media = generic.GenericRelation(ModelWithGeneric, content_type_field='content_type', object_id_field='object_id')
Example in Admin:
from django.contrib.contenttypes import generic from django.contrib import admin from apps.models import * class GenericInlineAdmin(generic.GenericTabularInline): model = ModelWithGeneric class ObjectAdmin(admin.ModelAdmin): inlines = ( GenericInlineAdmin, ) admin.site.register(ObjectWithGeneric, ObjectAdmin)
Error is: fk_name '<django.db.models.fields.related.ForeignKey object at 0x0319A1F0>' is not a ForeignKey to ContentType
Change History (9)
comment:1 by , 14 years ago
Owner: | changed from | to
---|
comment:2 by , 14 years ago
Owner: | removed |
---|
comment:3 by , 14 years ago
Owner: | set to |
---|
comment:4 by , 14 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:5 by , 14 years ago
Component: | Contrib apps → django.contrib.admin |
---|
comment:6 by , 14 years ago
Severity: | → Normal |
---|---|
Type: | → Bug |
comment:9 by , 5 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
ContentType
subclasses are not supported and raised contenttypes.E004
since Django 1.7 (see d818e0c9b2b88276cc499974f9eee893170bf0a8).
The line is now 374, inside generic_inlineformset_factory.