mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-07-24 07:19:36 +02:00
new image features
This commit is contained in:
parent
54d16e27b1
commit
5621e90665
7 changed files with 144 additions and 15 deletions
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',
|
||||
),
|
||||
]
|
Loading…
Add table
Add a link
Reference in a new issue