Surgo

lazy programmer. (simple is better than complex !)

Jan 19, 2009

DjangoのModelで複数のフィルターを利用する場合のTips

id:Voluntasが、早速コードレビューしてくださった。6つぐらいるけど、今日はとりあえず、Modelのリファクタリングのアドバイスを実装した。diffはここ

timeline = Timeline.all()
timeline = timeline.filter('author =', user)
timeline = timeline.filter('group =', group)
と今まで書いていたけど、Pythonは長いコードを'\'を使って改行できる。それを利用し、Modelで複数のfilterを利用する場合でも以下のように書く。
timeline = Timeline.all() \
  .filter('author =', user) \
  .filter('group =', group)
他にも色々とアドバイスを頂いているので、コードを見やすくしていくことにする。 Special thanks voluntas.

blog comments powered by Disqus

about

friends

archives

Kosei Kitahara.

surgo.jp at gmail.com

hosted at blogger.