fix remaining potential accessor name clashes (but this only works with Django 1.2+, for 1.1 no changes). Thanks to Andrew Ingram.

fix_request_path_info
Bert Constantin 2010-02-02 08:40:56 +01:00
parent ecaed2a71f
commit a99a3b5bfc
3 changed files with 30 additions and 9 deletions

View File

@ -379,10 +379,15 @@ Currently Unsupported Queryset Methods
Restrictions & Caveats Restrictions & Caveats
---------------------- ----------------------
* ``Django 1.1 only``: When ContentType is used in models, Django's * 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 seralisation or fixtures cannot be used. This issue seems to be
resolved for Django 1.2 (changeset 11863: Fixed #7052, resolved for Django 1.2 (changeset 11863: Fixed #7052, Added support
Added support for natural keys in serialization). for natural keys in serialization).
+ http://code.djangoproject.com/ticket/7052 + http://code.djangoproject.com/ticket/7052
+ http://stackoverflow.com/questions/853796/problems-with-contenttypes-when-loading-a-fixture-in-django + http://stackoverflow.com/questions/853796/problems-with-contenttypes-when-loading-a-fixture-in-django

View File

@ -24,3 +24,13 @@ class SModelB(SModelA):
class SModelC(SModelB): class SModelC(SModelB):
field3 = models.CharField(max_length=10) 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)

View File

@ -530,6 +530,8 @@ class PolymorphicModelBase(ModelBase):
################################################################################### ###################################################################################
### PolymorphicModel ### PolymorphicModel
from django import VERSION as django_VERSION
class PolymorphicModel(models.Model): class PolymorphicModel(models.Model):
""" """
Abstract base class that provides polymorphic behaviour Abstract base class that provides polymorphic behaviour
@ -556,10 +558,14 @@ class PolymorphicModel(models.Model):
class Meta: class Meta:
abstract = True abstract = True
# TODO: %(class)s alone is not really enough, we also need to include app_label - patch for Django needed? # avoid ContentType related field accessor clash (an error emitted by model validation)
# see: django/db/models/fields/related.py/RelatedField # we really should use both app_label and model name, but this is only possible since Django 1.2
polymorphic_ctype = models.ForeignKey(ContentType, if django_VERSION[0] <= 1 and django_VERSION[1] <= 1:
null=True, editable=False, related_name='polymorphic_%(class)s_set') 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 # some applications want to know the name of the fields that are added to its models
polymorphic_internal_model_fields = [ 'polymorphic_ctype' ] polymorphic_internal_model_fields = [ 'polymorphic_ctype' ]