Peewee - Update an entry with a dictionary
<p>I found <a href="https://stackoverflow.com/questions/22750439/peewee-how-to-convert-a-dict-into-a-model">this handy answer</a> on how to <strong>create</strong> a new table entry using a dictionary.</p>

<p>Now i'd like to <strong>update</strong> an entry with the same method. but i don't know how to adress the specific table entry that i'd like to update. </p>

<p>My current version looks like this:</p>

<pre><code>entries = Fruit.select().order_by(Fruit.name.desc())
#... all entries are listed with the index number
entry_index = int(input("Please enter entry number: "))
#...
entry_index -= 1

name = "Banana"
color = "yellow"

if input('Update entry? [Yn] ').lower() != 'n':
        entries[entry_index].name = name
        entries[entry_index].color = color
</code></pre>

<p>As you can see i adress every field explicitly.
I would like to put the variables (name, color) in a dictionary and update the entry at position "entry_index" with the fore-mentioned double-star-shortcut <a href="https://stackoverflow.com/questions/22750439/peewee-how-to-convert-a-dict-into-a-model">like in this answer</a>.
But i can't find a <a href="http://docs.peewee-orm.com/en/latest/peewee/querying.html#updating-existing-records" rel="nofollow">proper method in the docs</a>. </p>

<p>Does anyone know how to accomplish that?</p>

<p>Thanks for your help!</p>

<p>Muff</p>

<p>To update an object, you can:</p>

<pre><code>entry = entries_index[idx]
entry.something = 'new value'
entry.another_thing = 'another thing'
entry.save()
</code></pre>

<p>Alternatively:</p>

<pre><code>Entry.update(**{'something': 'new value', 'another_thing': 'another'}).where(Entry.id == entry.id).execute()
</code></pre>

<p>All of this is covered in the docs, please give them a thorough read. Follow the quick-start step by step and I think you will have a clearer idea of how to use peewee.</p>

python dictionary peewee