update_{FIELD_NAME} method to update only one field in a model.

48 views
Skip to first unread message

Vladimir Prudnikov

unread,
Sep 16, 2009, 9:11:13 AM9/16/09
to django-d...@googlegroups.com
Hello,
The default behaviour for saving object is very hard for big models, especially if it contain TextField. For example if I change one small field in a model and that run save() method it will generate UPDATE query for all of the fields which is very slow.

Instead of that I do it like that:

post.status = 2
Post.objects.filter(pk=post.pk).update(status=post.status)

This code will update only status field. So, my proposal is to add those special methods by default like that

post.update_status(2)

which will run query "UPDATE post_table SET post_table.status=1 WHERE id={POST_ID}" instead of updating all of the fields in case of running .save() method.

It's something like clean_{filedname} methods in the forms.

Karen Tracey

unread,
Sep 16, 2009, 10:08:03 AM9/16/09
to django-d...@googlegroups.com
On Wed, Sep 16, 2009 at 9:11 AM, Vladimir Prudnikov <pru...@gmail.com> wrote:
Hello,
The default behaviour for saving object is very hard for big models, especially if it contain TextField. For example if I change one small field in a model and that run save() method it will generate UPDATE query for all of the fields which is very slow.


There is an open ticket requesting this feature: http://code.djangoproject.com/ticket/4102

Karen
Reply all
Reply to author
Forward
0 new messages