Commit ff7f149b authored by Tom van Bussel's avatar Tom van Bussel
Browse files

Squashed photo digest migrations

parent 5fc4c8d2
# -*- coding: utf-8 -*-
# Generated by Django 1.10.4 on 2017-03-08 18:26
# Generated by Django 1.10.4 on 2017-03-22 19:59
from __future__ import unicode_literals
import hashlib
from django.db import migrations, models
def add_digests(apps, schema_editor):
Photo = apps.get_model('photos', 'Photo')
for photo in Photo.objects.all():
hash_sha1 = hashlib.sha1()
for chunk in iter(lambda: photo.file.read(4096), b""):
hash_sha1.update(chunk)
photo._digest = hash_sha1.hexdigest()
photo.save()
class Migration(migrations.Migration):
dependencies = [
......@@ -14,11 +24,15 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='photo',
name='_digest',
field=models.CharField(
default='',
blank=True,
max_length=40,
verbose_name='digest'),
field=models.CharField(blank=True, default='', max_length=40, verbose_name='digest'),
preserve_default=False,
),
migrations.RunPython(
code=add_digests,
),
migrations.AlterField(
model_name='Photo',
name='_digest',
field=models.CharField(max_length=40, verbose_name='digest'),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.10.4 on 2017-03-08 19:03
from __future__ import unicode_literals
import hashlib
from django.db import migrations
def add_digests(apps, schema_editor):
Photo = apps.get_model('photos', 'Photo')
for photo in Photo.objects.all():
hash_sha1 = hashlib.sha1()
for chunk in iter(lambda: photo.file.read(4096), b""):
hash_sha1.update(chunk)
photo._digest = hash_sha1.hexdigest()
photo.save()
class Migration(migrations.Migration):
dependencies = [
('photos', '0008_photo__digest'),
]
operations = [
migrations.RunPython(add_digests),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.10.4 on 2017-03-08 19:03
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('photos', '0009_generate_digests'),
]
operations = [
migrations.AlterField(
model_name='Photo',
name='_digest',
field=models.CharField(
max_length=40,
verbose_name='digest')),
]
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment