Skip to content

Commit

Permalink
Fix migration for updating media and comments count
Browse files Browse the repository at this point in the history
  • Loading branch information
josokinas committed May 19, 2019
1 parent d6f4e00 commit 55e9ae0
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
# -*- coding: utf-8 -*-

from django.db import migrations
from django.db import migrations, IntegrityError


def update_media_and_comments_count(apps, schema_editor):
Observation = apps.get_model('contributions', 'Observation')

for observation in Observation.objects.all():
observation.num_media = observation.files_attached.count()
observation.num_comments = observation.comments.count()
observation.save()
try:
observation.num_media = observation.files_attached.count()
observation.num_comments = observation.comments.count()
observation.save()
except IntegrityError:
pass


class Migration(migrations.Migration):
Expand Down

0 comments on commit 55e9ae0

Please sign in to comment.