latest changes

This commit is contained in:
Joren de Graaf
2026-10-07 14:33:21 +02:00
parent 86be3034c8
commit 98f76918dc
27 changed files with 1500 additions and 11 deletions
+3 -1
View File
@@ -17,7 +17,7 @@ from django.utils import timezone
from food.models import FoodProduct, Unit
logger = logging.getLogger(__name__)
FIELDS = 'code,product_name,brands,quantity,serving_size,serving_quantity,image_front_small_url,image_front_url,nutriments'
FIELDS = 'code,product_name,brands,quantity,serving_size,serving_quantity,image_front_small_url,image_front_url,nutriments,categories,categories_tags'
NUTRIENTS = {
'energy-kcal_100g': 'energy_kcal_100',
'carbohydrates_100g': 'carbohydrates_100',
@@ -154,6 +154,8 @@ def cached_product(user, barcode, *, refresh=False):
mapped['fetched_at'] = timezone.now()
nutrients = data.get('nutriments') if isinstance(data.get('nutriments'), dict) else {}
mapped['raw_data'] = {'code': barcode, 'product_name': mapped['product_name'],
'categories': str(data.get('categories') or '')[:1000],
'categories_tags': data.get('categories_tags', []) if isinstance(data.get('categories_tags'), list) else [],
'nutriments': {key: nutrients.get(key) for key in NUTRIENTS}}
product, _ = FoodProduct.objects.update_or_create(owner=user, barcode=barcode, defaults=mapped)
return product