Question:
How to insert new data into the table in Django?

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 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 are...




Answered by:> Willem Van Onsem

Credit:> Stackoverflow


Suggested reads:

>Plugins and Presets for Vuejs project

>Python Error Solved: load_associated_files do not load a txt file

>Python Error Solved: pg_config executable not found

>Set up Node.js & connect to a MongoDB Database Using Node.js

>Setting up a Cloud Composer environment: Step-by-step guide>How to merge cells with HTML, CSS, and PHP?

>How to Migrate your apps to Android 13


Ritu Singh

Ritu Singh

Submit
0 Answers