python - Commit manually in django -
is there better way following in django model method? following looks quite verbose, same in sql shell 1 line:
class itemmaster(models.model): ... @classmethod @transaction.commit_manually def update_imdb_rank(self): ''' update ranks imdbentry table ''' cursor = connection.cursor() cursor.execute("update main_itemmaster join mturk_imdbentry m using (imdb_url) set i.imdb_rank=m.imdb_rank") transaction.commit()
you can use with
statement reduce verbosity if wish:
class itemmaster(models.model): ... @classmethod def update_imdb_rank(self): transaction.atomic(): cursor = connection.cursor() cursor.execute("update main_itemmaster join mturk_imdbentry m using (imdb_url) set i.imdb_rank=m.imdb_rank")
Comments
Post a Comment