ensure creation file date
This commit is contained in:
parent
0eaff2266c
commit
8786f4b845
4 changed files with 46 additions and 5 deletions
24
core/files/migrations/0003_ensure_creation_date.py
Normal file
24
core/files/migrations/0003_ensure_creation_date.py
Normal file
|
@ -0,0 +1,24 @@
|
|||
# Generated by Django 4.2.7 on 2024-11-21 22:40
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
('files', '0002_alter_file_file'),
|
||||
]
|
||||
|
||||
def set_creation_date(apps, schema_editor):
|
||||
File = apps.get_model('files', 'File')
|
||||
for file in File.objects.all():
|
||||
if file.created_at is None:
|
||||
if not file.item.created_at is None:
|
||||
file.created_at = file.item.created_at
|
||||
else:
|
||||
file.created_at = max(File.objects.filter(
|
||||
id__lt=file.id, created_at__isnull=False).values_list('created_at', flat=True))
|
||||
file.save()
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(set_creation_date),
|
||||
]
|
Loading…
Add table
Add a link
Reference in a new issue