Skip to content

Commit

Permalink
Merge d56aba6 into 7077b7c
Browse files Browse the repository at this point in the history
  • Loading branch information
mkoistinen committed Apr 7, 2016
2 parents 7077b7c + d56aba6 commit 88972a2
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions cms/models/aliaspluginmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

@python_2_unicode_compatible
class AliasPluginModel(CMSPlugin):
cmsplugin_ptr = models.OneToOneField(CMSPlugin, related_name='cms_aliasplugin', parent_link=True)
plugin = models.ForeignKey(CMSPlugin, editable=False, related_name="alias_reference", null=True)
alias_placeholder = models.ForeignKey(Placeholder, editable=False, related_name="alias_placeholder", null=True)

Expand Down
5 changes: 1 addition & 4 deletions cms/models/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,7 @@ def search(self, q, language=None, current_site_only=True):
continue
field = cmsplugin.cmsplugin_ptr.field
related_query_name = field.related_query_name()
if (
related_query_name and
related_query_name != '+'
):
if related_query_name and not related_query_name.startswith('+'):
for field in cmsplugin.search_fields:
qp |= Q(**{
'placeholders__cmsplugin__{0}__{1}__icontains'.format(
Expand Down
2 changes: 1 addition & 1 deletion cms/models/placeholderpluginmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

@python_2_unicode_compatible
class PlaceholderReference(CMSPlugin):
cmsplugin_ptr = models.OneToOneField(CMSPlugin, related_name='cms_placeholderreference', parent_link=True)
name = models.CharField(max_length=255)
placeholder_ref = PlaceholderField(slotname='clipboard')

class Meta:
app_label = 'cms'

Expand Down
14 changes: 14 additions & 0 deletions cms/models/pluginmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,20 @@ def __new__(cls, name, bases, attrs):
# create a new class (using the super-metaclass)
new_class = super(PluginModelBase, cls).__new__(cls, name, bases, attrs)

# Set the one-to-one parent-child field to not create the reverse
# related descriptor to avoid name clashes for plugins with the same
# fieldnames. Skip this check if the parent-child field has been
# explicitly defined in the plugin subclass
#
# NOTE: We only do concrete classes, skipping the abstract ones
if 'cmsplugin_ptr' not in attrs and not new_class._meta.abstract:
for field in new_class._meta.fields:
if field.name == 'cmsplugin_ptr':
app_label = new_class._meta.app_label
model_name = new_class._meta.concrete_model._meta.model_name
field.rel.related_name = '{0}_{1}'.format(
app_label, model_name)

# if there is a RenderMeta in attrs, use this one
# else try to use the one from the superclass (if present)
meta = attr_meta or getattr(new_class, '_render_meta', None)
Expand Down

0 comments on commit 88972a2

Please sign in to comment.