3
0
Fork 0
mirror of https://github.com/nanoy42/coope synced 2024-11-04 17:06:27 +00:00
coope/users/migrations/0006_auto_20190611_0105.py

39 lines
1.3 KiB
Python
Raw Normal View History

2019-06-10 23:28:22 +00:00
# Generated by Django 2.1 on 2019-06-10 23:05
from django.db import migrations, models
def update(apps, schema_editor):
db_alias = schema_editor.connection.alias
users = apps.get_model('auth', 'User').objects.using(db_alias).all()
for user in users:
consumptions = apps.get_model('gestion', 'ConsumptionHistory').objects.using(db_alias).filter(customer=user).select_related('product')
alcohol = 0
for consumption in consumptions:
product = consumption.product
alcohol += consumption.quantity * float(product.deg) * product.volume * 0.79 /10 /1000
user.profile.alcohol = alcohol
user.profile.save()
def reverse_update(apps, schema_editor):
pass
class Migration(migrations.Migration):
dependencies = [
('users', '0005_auto_20190227_0859'),
]
operations = [
migrations.AddField(
model_name='historicalprofile',
name='alcohol',
field=models.DecimalField(decimal_places=2, default=0, max_digits=5, null=True),
),
migrations.AddField(
model_name='profile',
name='alcohol',
field=models.DecimalField(decimal_places=2, default=0, max_digits=5, null=True),
),
migrations.RunPython(update, reverse_update)
]