소스 검색

[foods] Add calories to food model

Colin Powell 1 개월 전
부모
커밋
cbf0583871
2개의 변경된 파일21개의 추가작업 그리고 1개의 파일을 삭제
  1. 18 0
      vrobbler/apps/foods/migrations/0003_food_calories.py
  2. 3 1
      vrobbler/apps/foods/models.py

+ 18 - 0
vrobbler/apps/foods/migrations/0003_food_calories.py

@@ -0,0 +1,18 @@
+# Generated by Django 4.2.19 on 2025-09-11 13:35
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('foods', '0002_alter_food_run_time_seconds'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='food',
+            name='calories',
+            field=models.IntegerField(blank=True, null=True),
+        ),
+    ]

+ 3 - 1
vrobbler/apps/foods/models.py

@@ -48,6 +48,7 @@ class FoodCategory(TimeStampedModel):
 
 class Food(ScrobblableMixin):
     description = models.TextField(**BNULL)
+    calories = models.IntegerField(**BNULL)
     allrecipe_image = models.ImageField(upload_to="food/recipe/", **BNULL)
     allrecipe_image_small = ImageSpecField(
         source="allrecipe_image",
@@ -72,7 +73,8 @@ class Food(ScrobblableMixin):
 
     @property
     def subtitle(self):
-        return self.category.name
+        if self.category:
+            return self.category.name
 
     @property
     def strings(self) -> ScrobblableConstants: