Skip to content

Commit

Permalink
Fix corner case with Django 1.7
Browse files Browse the repository at this point in the history
Conflicts:
	cms/models/placeholdermodel.py
  • Loading branch information
yakky committed Feb 22, 2015
1 parent 3fc5f84 commit 624f328
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions cms/models/placeholdermodel.py
Expand Up @@ -145,22 +145,30 @@ def _get_attached_fields(self):
"""
Returns an ITERATOR of all non-cmsplugin reverse foreign key related fields.
"""
from cms.models import CMSPlugin
if not hasattr(self, '_attached_fields_cache'):
from .pluginmodel import CMSPlugin
from ..admin.placeholderadmin import PlaceholderAdminMixin
self._attached_fields_cache = []
for rel in self._meta.get_all_related_objects():
if issubclass(rel.model, CMSPlugin):
continue
from cms.admin.placeholderadmin import PlaceholderAdminMixin
if rel.model in admin.site._registry and isinstance(admin.site._registry[rel.model], PlaceholderAdminMixin):
field = getattr(self, rel.get_accessor_name())
# this is required by Django 1.7 with sqlite backend as
# migrantions patches the db_table in certain circumstances
# and this patched db_table is preserved when contributing
# model to the field
field.model._meta.db_table = rel.model._meta.db_table
if field.count():
self._attached_fields_cache.append(rel.field)
return self._attached_fields_cache

def _get_attached_field(self):
from cms.models import CMSPlugin, StaticPlaceholder, Page
if not hasattr(self, '_attached_field_cache'):
from .pluginmodel import CMSPlugin
from .static_placeholder import StaticPlaceholder
from .pagemodel import Page
from ..admin.placeholderadmin import PlaceholderAdminMixin
self._attached_field_cache = None
relations = self._meta.get_all_related_objects()

Expand All @@ -170,9 +178,13 @@ def _get_attached_field(self):
for rel in relations:
if issubclass(rel.model, CMSPlugin):
continue
from cms.admin.placeholderadmin import PlaceholderAdminMixin
if rel.model in admin.site._registry and isinstance(admin.site._registry[rel.model], PlaceholderAdminMixin):
field = getattr(self, rel.get_accessor_name())
# this is required by Django 1.7 with sqlite backend as
# migrantions patches the db_table in certain circumstances
# and this patched db_table is preserved when contributing
# model to the field
field.model._meta.db_table = rel.model._meta.db_table
if field.count():
self._attached_field_cache = rel.field
break
Expand Down

0 comments on commit 624f328

Please sign in to comment.