Suppose I've got a model such as this:

class Book(models.Model):
    num_pages = ...
    author = ...
    date = ...

Can One produce a dictionary, after which place or update the model utilizing it?

d = {"num_pages":40, author:"Jack", date:"3324"}

Here's a good example of create making use of your dictionary d:


To update a current model, you will have to make use of the QuerySet filter method. Presuming you realize the pk from the Book you need to update:


Use ** for creating new. Loop with the dictionary and employ setattr() to be able to update a current model.

Knowing you need to create it:


Presuming you have to look for a current instance, you'll find it with get or create:

instance, created = Book.objects.get_or_create(slug=slug, defaults=d)
if not created:
    for value,attr in d.iteritems(): 
        setattr(instance, attr, value)

As pointed out in another answer, you may also make use of the update function around the queryset manager, however i believe that won't send any signals out (which might not matter for you discover with them). However, you most likely should not utilize it to change just one object: