1👍
✅
Add these to the defaults=…
parameter [Django-doc]:
AssignedTip.objects.update_or_create(
user_id=user,
date=day.date(),
defaults=dict(amount=user_amount, minutes=minutes),
)
or equivalent:
AssignedTip.objects.update_or_create(
user_id=user,
date=day.date(),
defaults={'amount': user_amount, 'minutes': minutes},
)
It thus will check if the user_id
and date
matches, and if so, update with the defaults=…
and if not create an item with that user_id
and date
and the defaults=…
.
Source:stackexchange.com