Просмотр исходного кода

[food] Add calories if they're missing

Colin Powell 14 часов назад
Родитель
Сommit
b0eb58953b
1 измененных файлов с 4 добавлено и 1 удалено
  1. 4 1
      vrobbler/apps/scrobbles/models.py

+ 4 - 1
vrobbler/apps/scrobbles/models.py

@@ -22,7 +22,7 @@ from django.db import models
 from django.urls import reverse
 from django.utils import timezone
 from django_extensions.db.models import TimeStampedModel
-from foods.models import Food
+from foods.models import Food, FoodLogData
 from imagekit.models import ImageSpecField
 from imagekit.processors import ResizeToFit
 from lifeevents.models import LifeEvent
@@ -1210,6 +1210,9 @@ class Scrobble(TimeStampedModel):
                 "source": source,
             },
         )
+        if mtype == cls.MediaType.FOOD and not scrobble_data.get("log", {}).get("calories", None):
+            if media.calories:
+                scrobble_data["log"] = FoodLogData(calories=media.calories)
 
         scrobble = cls.create(scrobble_data)
         return scrobble