45 lines
1.4 KiB
Python
45 lines
1.4 KiB
Python
import photologue.models
|
|
from django.db import migrations, models
|
|
|
|
|
|
def fill_dimensions(apps, schema_editor):
|
|
Photo = apps.get_model('photologue', 'Photo')
|
|
for photo in Photo.objects.filter(image_width__isnull=True).iterator():
|
|
try:
|
|
photo.image_width = photo.image.width
|
|
photo.image_height = photo.image.height
|
|
photo.save(update_fields=['image_width', 'image_height'])
|
|
except Exception:
|
|
pass
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
dependencies = [
|
|
('photologue', '0007_allow_duplicate_photo_titles'),
|
|
]
|
|
|
|
operations = [
|
|
migrations.AddField(
|
|
model_name='photo',
|
|
name='image_width',
|
|
field=models.PositiveIntegerField(editable=False, null=True),
|
|
),
|
|
migrations.AddField(
|
|
model_name='photo',
|
|
name='image_height',
|
|
field=models.PositiveIntegerField(editable=False, null=True),
|
|
),
|
|
migrations.RunPython(fill_dimensions, migrations.RunPython.noop),
|
|
migrations.AlterField(
|
|
model_name='photo',
|
|
name='image',
|
|
field=models.ImageField(
|
|
max_length=100,
|
|
upload_to=photologue.models.get_storage_path,
|
|
verbose_name='image',
|
|
width_field='image_width',
|
|
height_field='image_height',
|
|
),
|
|
),
|
|
]
|