#25122: GenericRelation with a string argument will raise an AttributeError when
accessed.
-------------------------------------+-------------------------------------
Reporter: martin-c | Owner: nobody
Type: Bug | Status: new
Component: | Version: 1.8
contrib.contenttypes | Keywords: GenericRelation,
Severity: Normal | AttributeError
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
In other relationship fields it is possible to specify the target model by
passing its model name as a string, such as
{{{
#!python
class Car(models.Model):
manufacturer = models.ForeignKey('production.Manufacturer')
}}}
However, in the case of a GenericRelation,
{{{
#!python
class Car(models.Model):
manufacturers = GenericRelation('production.Manufacturer')
}}}
accessing the manufacturers field will cause a AttributeError to be
raised.
{{{
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Users/.../.python-env/lib/python2.7/site-
packages/django/contrib/contenttypes/fields.py", line 406, in __get__
superclass = rel_model._default_manager.__class__
AttributeError: 'unicode' object has no attribute '_default_manager'
}}}
So it seems only the target class instance can be passed to
GenericRelation().
--
Ticket URL: <https://code.djangoproject.com/ticket/25122>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.