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 matiasb, 14 years ago

Owner: changed from nobody to matiasb

comment:2 by matiasb, 14 years ago

Owner: matiasb removed

comment:3 by matiasb, 14 years ago

Owner: set to nobody

comment:4 by Russell Keith-Magee, 14 years ago

Triage Stage: UnreviewedAccepted

The line is now 374, inside generic_inlineformset_factory.

comment:5 by Julien Phalip, 14 years ago

Component: Contrib appsdjango.contrib.admin

comment:6 by Julien Phalip, 13 years ago

Severity: Normal
Type: Bug

comment:7 by Aymeric Augustin, 13 years ago

UI/UX: unset

Change UI/UX from NULL to False.

comment:8 by Aymeric Augustin, 13 years ago

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:9 by Mariusz Felisiak, 5 years ago

Resolution: invalid
Status: newclosed

ContentType subclasses are not supported and raised contenttypes.E004 since Django 1.7 (see d818e0c9b2b88276cc499974f9eee893170bf0a8).

Note: See TracTickets for help on using tickets.
Back to Top