home / django_tickets / tickets

tickets: 8309

This data as json

id created changetime last_pulled_from_trac stage status component type severity version resolution summary description owner reporter keywords easy has_patch needs_better_patch needs_tests needs_docs ui_ux
8309 2008-08-14 13:46:52 2011-09-28 16:12:17 2022-03-06 03:41:54.629989 Accepted closed Contrib apps     dev fixed GenericForeignKey fails when used in abstract base models The following code will reproduce this bug: {{{ # aaa/models.py from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes import generic class MyModel(models.Model): field = models.IntegerField() class TaggedItemBase(models.Model): class Meta: abstract = True content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() content_object = generic.GenericForeignKey() class TaggedItem(TaggedItemBase): """A tag on an item.""" tag = models.SlugField() class Meta: ordering = ["tag"] def __unicode__(self): return self.tag # From command shell >>> from aaa.models import MyModel, TaggedItem >>> m = MyModel(field=1) >>> m.save() >>> t = TaggedItem(content_object=m, tag="my") Traceback (most recent call last): File "<console>", line 1, in ? File "/usr/lib/python2.4/site-packages/django/db/models/base.py", line 240, in __init__ raise TypeError, "'%s' is an invalid keyword argument for this function" % kwargs.keys()[0] TypeError: 'content_object' is an invalid keyword argument for this function }}} If we do not use model inheritance, the script works fine. jacob Wonlay GenericForeignKey , model inheritance 0 1 0 0 0 0
Powered by Datasette · Queries took 1.028ms