@@ -11,9 +11,11 @@ def move_webhooks(apps, schema_editor):
11
11
Webhook = apps .get_model ("extras" , "Webhook" )
12
12
EventRule = apps .get_model ("extras" , "EventRule" )
13
13
14
+ webhook_ct = ContentType .objects .get_for_model (Webhook ).pk
14
15
for webhook in Webhook .objects .all ():
15
16
event = EventRule ()
16
17
18
+ # Replicate attributes from Webhook instance
17
19
event .name = webhook .name
18
20
event .type_create = webhook .type_create
19
21
event .type_update = webhook .type_update
@@ -24,7 +26,7 @@ def move_webhooks(apps, schema_editor):
24
26
event .conditions = webhook .conditions
25
27
26
28
event .action_type = EventRuleActionChoices .WEBHOOK
27
- event .action_object_type_id = ContentType . objects . get_for_model ( webhook ). id
29
+ event .action_object_type_id = webhook_ct
28
30
event .action_object_id = webhook .id
29
31
event .save ()
30
32
event .content_types .add (* webhook .content_types .all ())
@@ -37,6 +39,8 @@ class Migration(migrations.Migration):
37
39
]
38
40
39
41
operations = [
42
+
43
+ # Create the EventRule model
40
44
migrations .CreateModel (
41
45
name = 'EventRule' ,
42
46
fields = [
@@ -68,7 +72,30 @@ class Migration(migrations.Migration):
68
72
'ordering' : ('name' ,),
69
73
},
70
74
),
75
+ migrations .AddField (
76
+ model_name = 'eventrule' ,
77
+ name = 'action_object_type' ,
78
+ field = models .ForeignKey (
79
+ on_delete = django .db .models .deletion .CASCADE ,
80
+ related_name = 'eventrule_actions' ,
81
+ to = 'contenttypes.contenttype' ,
82
+ ),
83
+ ),
84
+ migrations .AddField (
85
+ model_name = 'eventrule' ,
86
+ name = 'content_types' ,
87
+ field = models .ManyToManyField (related_name = 'eventrules' , to = 'contenttypes.contenttype' ),
88
+ ),
89
+ migrations .AddField (
90
+ model_name = 'eventrule' ,
91
+ name = 'tags' ,
92
+ field = taggit .managers .TaggableManager (through = 'extras.TaggedItem' , to = 'extras.Tag' ),
93
+ ),
94
+
95
+ # Replicate Webhook data
71
96
migrations .RunPython (move_webhooks ),
97
+
98
+ # Remove obsolete fields from Webhook
72
99
migrations .RemoveConstraint (
73
100
model_name = 'webhook' ,
74
101
name = 'extras_webhook_unique_payload_url_types' ,
@@ -105,25 +132,8 @@ class Migration(migrations.Migration):
105
132
model_name = 'webhook' ,
106
133
name = 'type_update' ,
107
134
),
108
- migrations .AddField (
109
- model_name = 'eventrule' ,
110
- name = 'action_object_type' ,
111
- field = models .ForeignKey (
112
- on_delete = django .db .models .deletion .CASCADE ,
113
- related_name = 'eventrule_actions' ,
114
- to = 'contenttypes.contenttype' ,
115
- ),
116
- ),
117
- migrations .AddField (
118
- model_name = 'eventrule' ,
119
- name = 'content_types' ,
120
- field = models .ManyToManyField (related_name = 'eventrules' , to = 'contenttypes.contenttype' ),
121
- ),
122
- migrations .AddField (
123
- model_name = 'eventrule' ,
124
- name = 'tags' ,
125
- field = taggit .managers .TaggableManager (through = 'extras.TaggedItem' , to = 'extras.Tag' ),
126
- ),
135
+
136
+ # Add description field to Webhook
127
137
migrations .AddField (
128
138
model_name = 'webhook' ,
129
139
name = 'description' ,
0 commit comments