+ book = Book.objects.get(pk=book_id)
+ out = transform(book.wldocument())
+ field_name = '%s_file' % ext
+ # Update instead of saving the model to avoid race condition.
+ getattr(book, field_name).save('%s.%s' % (book.slug, ext),
+ File(open(out.get_filename())),
+ save=False
+ )
+ Book.objects.filter(pk=book_id).update(**{
+ field_name: getattr(book, field_name)
+ })
+