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

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -