#27460: GenericRelation doesn't work from AbstractClass to AbstractClass in
Django
1.10(.3)
-------------------------------------+-------------------------------------
Reporter: Wolfgang Grim | Owner: nobody
Type: Bug | Status: new
Component: Core (Other) | Version: 1.10
Severity: Normal | Resolution:
Keywords: GenericRelation, | Triage Stage:
Abstract, ContentFramework | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Wolfgang Grim):
Hmm I also don't get it to run now - But I can explain what I want to
achieve:
models.py
{{{
from __future__ import unicode_literals
from django.db import models
from django.contrib.contenttypes.fields import GenericForeignKey,
GenericRelation
from django.contrib.contenttypes.models import ContentType
class AbstractMaster (models.Model):
class Meta: abstract=True
detailModel_type = models.ForeignKey(ContentType, blank=True,
null=True)
detailModel_id = models.PositiveIntegerField(blank=True, null=True)
detail_Model = GenericForeignKey('detailModel_type', 'detailModel_id')
class AbstractDetail (models.Model):
class Meta: abstract=True
name = models.CharField (max_length=255, null=True)
masterModel_type = models.ForeignKey(ContentType, blank=True,
null=True)
masterModel_id = models.PositiveIntegerField(blank=True, null=True)
master_Model = GenericForeignKey('masterModel_type', 'masterModel_id')
relatedMasterModel = GenericRelation(AbstractMaster,
object_id_field='detailModel_id', content_type_field='detailModel_id',
related_query_name='%(app_label)s_%(class)s_detail_model')
class MasterTest (AbstractMaster):
pass
class DetailTest (AbstractDetail):
pass
}}}
python manage.py shell
{{{
from testac.models import MasterTest, DetailTest
mt = MasterTest.objects.create()
dt = DetailTest.objects.create(name="Test")
mt.detail_Model = dt
mt.save()
dt.master_Model = mt
dt.save()
mt.detail_Model.name
# Out[8]: 'Test' (So this is working)
MasterTest.objects.filter(detail_Model__name="Test")
# Throws: FieldError: Field 'detail_Model' does not generate an automatic
reverse relation and therefore cannot be used for reverse querying. If it
is a GenericForeignKey, consider adding a GenericRelation.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/27460#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/064.63b5a0658905ac5ebb931e28fcbf3f13%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.