Skip to content

Commit 4063fef

Browse files
committed
chore: add allow_download field to existing Document records
--bug=1060848 --user=刘瑞斌 【知识库】文档设置[允许知识库来源中下载 ]应该默认开启 https://www.tapd.cn/62980211/s/1762365
1 parent b5cd3f9 commit 4063fef

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

apps/knowledge/migrations/0002_alter_file_source_type.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,23 @@
22

33
from django.db import migrations, models
44

5+
from django.db.models import Q
6+
7+
8+
def add_allow_download_to_existing_documents(apps, schema_editor):
9+
Document = apps.get_model('knowledge', 'Document')
10+
11+
# 为所有现有的Document记录添加allow_download=True
12+
documents = Document.objects.filter(
13+
Q(meta__isnull=True) |
14+
~Q(meta__has_key='allow_download')
15+
)
16+
17+
for doc in documents:
18+
if doc.meta is None:
19+
doc.meta = {}
20+
doc.meta['allow_download'] = True
21+
doc.save(update_fields=['meta'])
522

623
class Migration(migrations.Migration):
724

@@ -15,4 +32,5 @@ class Migration(migrations.Migration):
1532
name='source_type',
1633
field=models.CharField(choices=[('KNOWLEDGE', 'Knowledge'), ('APPLICATION', 'Application'), ('TOOL', 'Tool'), ('DOCUMENT', 'Document'), ('CHAT', 'Chat'), ('SYSTEM', 'System'), ('TEMPORARY_30_MINUTE', 'Temporary 30 Minute'), ('TEMPORARY_120_MINUTE', 'Temporary 120 Minute'), ('TEMPORARY_1_DAY', 'Temporary 1 Day')], db_index=True, default='TEMPORARY_120_MINUTE', verbose_name='资源类型'),
1734
),
35+
migrations.RunPython(add_allow_download_to_existing_documents)
1836
]

0 commit comments

Comments
 (0)