new image features
This commit is contained in:
29
backend/server/adventures/migrations/migrate_images.py
Normal file
29
backend/server/adventures/migrations/migrate_images.py
Normal file
@@ -0,0 +1,29 @@
|
||||
from django.db import migrations
|
||||
|
||||
def move_images_to_new_model(apps, schema_editor):
|
||||
Adventure = apps.get_model('adventures', 'Adventure')
|
||||
AdventureImage = apps.get_model('adventures', 'AdventureImage')
|
||||
|
||||
for adventure in Adventure.objects.all():
|
||||
if adventure.image:
|
||||
AdventureImage.objects.create(
|
||||
adventure=adventure,
|
||||
image=adventure.image,
|
||||
user_id=adventure.user_id,
|
||||
)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('adventures', '0001_initial'),
|
||||
('adventures', '0002_adventureimage'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(move_images_to_new_model),
|
||||
migrations.RemoveField(
|
||||
model_name='Adventure',
|
||||
name='image',
|
||||
),
|
||||
]
|
||||
Reference in New Issue
Block a user