1 # Generated by Django 4.0.8 on 2024-02-21 11:55
3 from django.db import migrations, models
6 def populate_spent(apps, schema_editor):
7 Offer = apps.get_model('funding', 'Offer')
8 Spent = apps.get_model('funding', 'Spent')
9 Book = apps.get_model('catalogue', 'Book')
10 for o in Offer.objects.all():
11 if Spent.objects.filter(book__slug=o.slug).exists():
13 s = o.funding_set.exclude(completed_at=None).aggregate(s=models.Sum('amount'))['s'] or 0
16 book = Book.objects.get(slug=o.slug)
18 except Book.DoesNotExist:
30 class Migration(migrations.Migration):
33 ('funding', '0012_spent_annotation_spent_link_alter_spent_book'),
39 migrations.RunPython.noop