mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-08-10 00:18:57 +00:00
Allow setting more than one tag in mail rules
The three migrations do the following to preserve existing data in assign_tag: 1. Add the new many-to-many field assign_tags. 2. Copy existing data from the assign_tag field to the assign_tags. 3. Delete the existing assign_tag field.
This commit is contained in:
23
src/paperless_mail/migrations/0009_mailrule_assign_tags.py
Normal file
23
src/paperless_mail/migrations/0009_mailrule_assign_tags.py
Normal file
@@ -0,0 +1,23 @@
|
||||
# Generated by Django 3.2.12 on 2022-03-11 15:00
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("paperless_mail", "0008_auto_20210516_0940"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="mailrule",
|
||||
name="assign_tags",
|
||||
field=models.ManyToManyField(
|
||||
blank=True,
|
||||
related_name="mail_rules_multi",
|
||||
to="documents.Tag",
|
||||
verbose_name="assign this tag",
|
||||
),
|
||||
),
|
||||
]
|
26
src/paperless_mail/migrations/0010_auto_20220311_1602.py
Normal file
26
src/paperless_mail/migrations/0010_auto_20220311_1602.py
Normal file
@@ -0,0 +1,26 @@
|
||||
# Generated by Django 3.2.12 on 2022-03-11 15:02
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
def migrate_tag(apps, schema_editor):
|
||||
# Manual data migration, see
|
||||
# https://docs.djangoproject.com/en/3.2/topics/migrations/#data-migrations
|
||||
#
|
||||
# Copy the assign_tag property to the new assign_tags set if it exists.
|
||||
MailRule = apps.get_model("paperless_mail", "MailRule")
|
||||
for mail_rule in MailRule.objects.all():
|
||||
if mail_rule.assign_tag:
|
||||
mail_rule.assign_tags.add(mail_rule.assign_tag)
|
||||
mail_rule.save()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("paperless_mail", "0009_mailrule_assign_tags"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(migrate_tag),
|
||||
]
|
@@ -0,0 +1,17 @@
|
||||
# Generated by Django 3.2.12 on 2022-03-11 15:18
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("paperless_mail", "0010_auto_20220311_1602"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name="mailrule",
|
||||
name="assign_tag",
|
||||
),
|
||||
]
|
Reference in New Issue
Block a user