fix remaining potential accessor name clashes (but this only works with Django 1.2+, for 1.1 no changes). Thanks to Andrew Ingram.
parent
ecaed2a71f
commit
a99a3b5bfc
15
DOCS.rst
15
DOCS.rst
|
|
@ -379,11 +379,16 @@ Currently Unsupported Queryset Methods
|
|||
Restrictions & Caveats
|
||||
----------------------
|
||||
|
||||
* ``Django 1.1 only``: When ContentType is used in models, Django's
|
||||
seralisation or fixtures cannot be used. This issue seems to be
|
||||
resolved for Django 1.2 (changeset 11863: Fixed #7052,
|
||||
Added support for natural keys in serialization).
|
||||
|
||||
* Django 1.1 only - the names of polymorphic models must be unique
|
||||
in the whole project, even if they are in two different apps.
|
||||
This results from a restriction in the Django 1.1 "related_name"
|
||||
option (fixed in Django 1.2).
|
||||
|
||||
* Django 1.1 only - when ContentType is used in models, Django's
|
||||
seralisation or fixtures cannot be used. This issue seems to be
|
||||
resolved for Django 1.2 (changeset 11863: Fixed #7052, Added support
|
||||
for natural keys in serialization).
|
||||
|
||||
+ http://code.djangoproject.com/ticket/7052
|
||||
+ http://stackoverflow.com/questions/853796/problems-with-contenttypes-when-loading-a-fixture-in-django
|
||||
|
||||
|
|
|
|||
|
|
@ -24,3 +24,13 @@ class SModelB(SModelA):
|
|||
class SModelC(SModelB):
|
||||
field3 = models.CharField(max_length=10)
|
||||
|
||||
# for Django 1.2+, test models with same names in different apps
|
||||
# (the other models with identical names are in polymorphic/tests.py)
|
||||
from django import VERSION as django_VERSION
|
||||
if not (django_VERSION[0]<=1 and django_VERSION[1]<=1):
|
||||
class Model2A(PolymorphicModel):
|
||||
field1 = models.CharField(max_length=10)
|
||||
class Model2B(Model2A):
|
||||
field2 = models.CharField(max_length=10)
|
||||
class Model2C(Model2B):
|
||||
field3 = models.CharField(max_length=10)
|
||||
|
|
|
|||
|
|
@ -530,6 +530,8 @@ class PolymorphicModelBase(ModelBase):
|
|||
###################################################################################
|
||||
### PolymorphicModel
|
||||
|
||||
from django import VERSION as django_VERSION
|
||||
|
||||
class PolymorphicModel(models.Model):
|
||||
"""
|
||||
Abstract base class that provides polymorphic behaviour
|
||||
|
|
@ -556,10 +558,14 @@ class PolymorphicModel(models.Model):
|
|||
class Meta:
|
||||
abstract = True
|
||||
|
||||
# TODO: %(class)s alone is not really enough, we also need to include app_label - patch for Django needed?
|
||||
# see: django/db/models/fields/related.py/RelatedField
|
||||
polymorphic_ctype = models.ForeignKey(ContentType,
|
||||
null=True, editable=False, related_name='polymorphic_%(class)s_set')
|
||||
# avoid ContentType related field accessor clash (an error emitted by model validation)
|
||||
# we really should use both app_label and model name, but this is only possible since Django 1.2
|
||||
if django_VERSION[0] <= 1 and django_VERSION[1] <= 1:
|
||||
p_related_name_template = 'polymorphic_%(class)s_set'
|
||||
else:
|
||||
p_related_name_template = 'polymorphic_%(app_label)s.%(class)s_set'
|
||||
polymorphic_ctype = models.ForeignKey(ContentType, null=True, editable=False,
|
||||
related_name=p_related_name_template)
|
||||
|
||||
# some applications want to know the name of the fields that are added to its models
|
||||
polymorphic_internal_model_fields = [ 'polymorphic_ctype' ]
|
||||
|
|
|
|||
Loading…
Reference in New Issue