Skip to content

Commit

Permalink
Merge pull request #625 from johannaengland/notificationprofile/copy-…
Browse files Browse the repository at this point in the history
…filter-str-to-filter

Copy content of filter_string to filter
  • Loading branch information
johannaengland authored Apr 28, 2023
2 parents 42bd9de + 01d9e47 commit 423c779
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import json

from django.db import migrations


def copy_filter_string_to_filter(apps, schema_editor):
Filter = apps.get_model("argus_notificationprofile", "Filter")
for f in Filter.objects.all():
changed = False
filter_json = json.loads(f.filter_string)
for key in filter_json.keys():
if filter_json[key] and (f.filter.get(key, None) != filter_json[key]):
f.filter[key] = filter_json[key]
changed = True
if changed:
f.save()


class Migration(migrations.Migration):
dependencies = [
("argus_notificationprofile", "0011_media_installed_alter_media_slug_and_more"),
]

operations = [
migrations.RunPython(copy_filter_string_to_filter, migrations.RunPython.noop),
]

0 comments on commit 423c779

Please sign in to comment.