Browse Source

Add upload_name field to Example model

pull/1779/head
Hironsan 2 years ago
parent
commit
8c2cdbc401
7 changed files with 84 additions and 3 deletions
  1. 5
      backend/examples/migrations/0001_initial.py
  2. 2
      backend/examples/migrations/0002_alter_example_project.py
  3. 24
      backend/examples/migrations/0003_alter_example_filename.py
  4. 18
      backend/examples/migrations/0004_example_upload_name.py
  5. 19
      backend/examples/migrations/0005_auto_20220405_0252.py
  6. 18
      backend/examples/migrations/0006_alter_example_upload_name.py
  7. 1
      backend/examples/models.py

5
backend/examples/migrations/0001_initial.py

@ -1,9 +1,10 @@
# Generated by Django 3.2.11 on 2022-01-28 02:46
import uuid
import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import uuid
class Migration(migrations.Migration):

2
backend/examples/migrations/0002_alter_example_project.py

@ -1,7 +1,7 @@
# Generated by Django 3.2.11 on 2022-02-04 02:01
from django.db import migrations, models
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):

24
backend/examples/migrations/0003_alter_example_filename.py

@ -0,0 +1,24 @@
# Generated by Django 4.0.2 on 2022-04-05 02:46
import django_drf_filepond.models
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("examples", "0002_alter_example_project"),
]
operations = [
migrations.AlterField(
model_name="example",
name="filename",
field=models.FileField(
default=".",
max_length=1024,
storage=django_drf_filepond.models.FilePondLocalStoredStorage(),
upload_to="",
),
),
]

18
backend/examples/migrations/0004_example_upload_name.py

@ -0,0 +1,18 @@
# Generated by Django 4.0.2 on 2022-04-05 02:46
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("examples", "0003_alter_example_filename"),
]
operations = [
migrations.AddField(
model_name="example",
name="upload_name",
field=models.CharField(blank=True, max_length=512, null=True),
),
]

19
backend/examples/migrations/0005_auto_20220405_0252.py

@ -0,0 +1,19 @@
import os
from django.db import migrations
def store_filename(apps, schema_editor):
Example = apps.get_model("examples", "Example")
for example in Example.objects.all():
example.upload_name = os.path.basename(example.filename.name)
example.save()
class Migration(migrations.Migration):
dependencies = [
("examples", "0004_example_upload_name"),
]
operations = [migrations.RunPython(code=store_filename, reverse_code=migrations.RunPython.noop)]

18
backend/examples/migrations/0006_alter_example_upload_name.py

@ -0,0 +1,18 @@
# Generated by Django 4.0.2 on 2022-04-05 02:59
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("examples", "0005_auto_20220405_0252"),
]
operations = [
migrations.AlterField(
model_name="example",
name="upload_name",
field=models.CharField(max_length=512),
),
]

1
backend/examples/models.py

@ -14,6 +14,7 @@ class Example(models.Model):
uuid = models.UUIDField(default=uuid.uuid4, editable=False, db_index=True, unique=True)
meta = models.JSONField(default=dict)
filename = models.FileField(default=".", max_length=1024, storage=DrfFilePondStoredStorage())
upload_name = models.CharField(max_length=512)
project = models.ForeignKey(to=Project, on_delete=models.CASCADE, related_name="examples")
annotations_approved_by = models.ForeignKey(to=User, on_delete=models.SET_NULL, null=True, blank=True)
text = models.TextField(null=True, blank=True)

Loading…
Cancel
Save