Skip to content

Commit

Permalink
new action field as foreign key
Browse files Browse the repository at this point in the history
  • Loading branch information
Svyat committed Jun 5, 2024
1 parent 51787a9 commit e2361f1
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 3 deletions.
1 change: 1 addition & 0 deletions triggers/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class ConditionInline(StackedPolymorphicInline):
class ActionInline(StackedPolymorphicInline):
model = Action
child_inlines = generate_child_inlines(Action)
fk_name = "trigger"


class EventInline(StackedPolymorphicInline):
Expand Down
15 changes: 12 additions & 3 deletions triggers/migrations/0004_alter_action_trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,25 @@
import django.db.models.deletion


def save_action_triggers(apps, schema_editor):
Action = apps.get_model("triggers", "Action")
for action in Action.objects.all():
action.trigger_new_id = action.trigger_id
action.save()


class Migration(migrations.Migration):

dependencies = [
('triggers', '0003_event_delay'),
]

operations = [
migrations.AlterField(
migrations.AddField(
model_name='action',
name='trigger',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='actions', related_query_name='action', to='triggers.trigger', verbose_name='trigger'),
name='trigger_new',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='actions_new',
related_query_name='action_new', to='triggers.trigger', verbose_name='trigger'),
),
migrations.RunPython(save_action_triggers, reverse_code=migrations.RunPython.noop),
]
44 changes: 44 additions & 0 deletions triggers/migrations/0005_alter_action_triggers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Generated by Django 3.2.20 on 2024-06-04 05:14

from django.db import migrations, models
import django.db.models.deletion


def save_action_triggers(apps, schema_editor):
Action = apps.get_model("triggers", "Action")
for action in Action.objects.all():
action.trigger_new_id = action.trigger_id
action.save()


class Migration(migrations.Migration):

dependencies = [
('triggers', '0004_alter_action_trigger'),
]

operations = [
migrations.RenameField(
model_name='action',
old_name='trigger',
new_name='trigger_old',
),
migrations.RenameField(
model_name='action',
old_name='trigger_new',
new_name='trigger',
),
migrations.AlterField(
model_name='action',
name='trigger',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='actions',
related_query_name='action', to='triggers.trigger', verbose_name='trigger'),
),
migrations.AlterField(
model_name='action',
name='trigger_old',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE,
related_name='actions_old', related_query_name='action_old', to='triggers.trigger',
verbose_name='trigger obsolete'),
),
]
10 changes: 10 additions & 0 deletions triggers/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@ class Action(PolymorphicModel):
related_name='actions',
related_query_name='action',
verbose_name=_('trigger'),
null=True
)
trigger_old = models.ForeignKey(
to=Trigger,
on_delete=models.CASCADE,
related_name='actions_old',
related_query_name='action_old',
verbose_name=_('trigger obsolete'),
null=True,
blank=True,
)

class Meta:
Expand Down

0 comments on commit e2361f1

Please sign in to comment.