You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

19 lines
495 B

  1. import os
  2. from django.db import migrations
  3. def store_filename(apps, schema_editor):
  4. Example = apps.get_model("examples", "Example")
  5. for example in Example.objects.all():
  6. example.upload_name = os.path.basename(example.filename.name)
  7. example.save()
  8. class Migration(migrations.Migration):
  9. dependencies = [
  10. ("examples", "0004_example_upload_name"),
  11. ]
  12. operations = [migrations.RunPython(code=store_filename, reverse_code=migrations.RunPython.noop)]