Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrated Placeholder source field (#6496)
- Loading branch information
1 parent
39562ae
commit b075f44
Showing
31 changed files
with
442 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.11 on 2018-08-24 08:22 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations | ||
|
||
|
||
def forwards(apps, schema_editor): | ||
db_alias = schema_editor.connection.alias | ||
ContentType = apps.get_model('contenttypes', 'ContentType') | ||
CMSPlugin = apps.get_model('cms', 'CMSPlugin') | ||
Placeholder = apps.get_model('cms', 'Placeholder') | ||
|
||
for app in apps.get_app_configs(): | ||
for model_class in app.get_models(): | ||
if issubclass(model_class, (CMSPlugin, Placeholder)): | ||
# We ignore all models inherited from CMSPlugin or Placeholder. | ||
continue | ||
|
||
# Get all fields which has a relationship to Placeholder. | ||
pl_related_fields = [ | ||
f for f in model_class._meta.get_fields() | ||
if f.related_model == Placeholder and not f.auto_created | ||
] | ||
|
||
if not pl_related_fields: | ||
# Model has no related fields with Placeholder. | ||
continue | ||
|
||
# Model has related field/s with Placeholder. | ||
# Now get all the objects for the model and populate source field. | ||
cur_ct_obj = ContentType.objects.get_for_model(model_class) | ||
|
||
for obj in model_class.objects.using(db_alias): | ||
for pl_field in pl_related_fields: | ||
obj_placeholder_field = getattr(obj, pl_field.name) | ||
|
||
if pl_field.many_to_many: | ||
obj_placeholder_field.update( | ||
content_type_id=cur_ct_obj.pk, | ||
object_id=obj.pk, | ||
) | ||
else: | ||
obj_placeholder_field.content_type_id = cur_ct_obj.pk, | ||
obj_placeholder_field.object_id = obj.pk | ||
obj.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('cms', '0032_remove_title_to_pagecontent'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(forwards), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.11 on 2018-08-30 15:49 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('cms', '0033_placeholder_source_data_migration'), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveField( | ||
model_name='pagecontent', | ||
name='placeholders', | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Oops, something went wrong.