SlideShare a Scribd company logo
Django O/R Mapper
I'll be giving this presentation in English. このプレゼンを英語でさせて頂きます。
Just joking. 嘘です。
自己紹介 名前: イアン・ルイス  ( Ian Lewis )‏ 年齢: 27 歳 国籍:米国 Twitter: IanMLewis ( 80 %日本語) HP: http://www.ianlewis.org/ 所属 : BeProud   好きな物: 勉強。挑戦。 Python 。
Ask me questions anytime. いつでも、質問をしても良い
Why an O/R Mapper? >>>  import  MySQLdb >>> db=MySQLdb. connect (passwd= &quot;moonpie&quot; ,db= &quot;mydb&quot; ) >>>  >>> c=db. cursor () >>> max_price=5 >>> c. execute ( &quot;&quot;&quot;SELECT name, spam, eggs, sausage FROM breakfast ...  WHERE price <  %s &quot;&quot;&quot; , (max_price,)) >>> c. fetchall () ( ( &quot;Spam and Sausage Lover's Plate&quot; , 5L, 1L, 8L ), ( &quot;Not So Much Spam Plate&quot; , 3L, 2L, 0L ), ( &quot;Don't Wany ANY SPAM! Plate&quot; , 0L, 4L, 3L ) ) >>>   c.executemany( ...  &quot;&quot;&quot;INSERT INTO breakfast (name, spam, eggs, sausage, price) ...  VALUES ( %s ,  %s ,  %s ,  %s ,  %s )&quot;&quot;&quot; , ... [ ... ( &quot;Spam and Sausage Lover's Plate&quot; , 5, 1, 8, 7.95 ), ... ( &quot;Not So Much Spam Plate&quot; , 3, 2, 0, 3.95 ), ... ( &quot;Don't Wany ANY SPAM! Plate&quot; , 0, 4, 3, 5.95 ) ... ] )‏
Not Good. よろしくないね
Models  Objects Database
Ok, Let's make a model さて、モデルを作りましょう
Models class  Feed (models.Model):      '''A RSS/Atom feed.'''     feed_lifestream = models. ForeignKey (Lifestream)          feed_name = models. CharField ( &quot;Feed Name&quot; , max_length=255)     feed_url = models. URLField ( &quot;Feed Url&quot; , verify_exists=True, max_length=1000)     feed_domain = models. CharField ( &quot;Feed Domain&quot; , max_length=255)     feed_fetchable = models. BooleanField ( &quot;Is Feed Fetchable?&quot; , default=True)         # Used for feeds that allow users to directly add to the lifestream.     feed_basic_feed = models. BooleanField ( &quot;Is Basic Feed?&quot; , default=False)        objects =  FeedManager ()        def  __unicode__ (self):         return self.feed_name          class  Meta :         db_table= &quot;feeds&quot;
Relationships class  Item (models.Model):    '''A feed item'''    # One to many relationship    item_feed = models. ForeignKey ( &quot;Item Feed&quot; , Feed)   item_date = models. DateTimeField ( &quot;Publish Date&quot; )   item_title = models. CharField ( &quot;Title&quot; , max_length=255)   item_content = models. TextField ( &quot;Item Content&quot; , null=True, blank=True)   item_permalink = models. UrlField ( &quot;Permalink&quot; , max_length=1000)‏    # Many to Many relationship    item_tags = models. ManyToManyField (Tag, null=True, blank=True, db_table=&quot;item_tags&quot;)‏    ...
Database Sync [email_address]   ~/src/dlife/dlife $ python manage.py syncdb Creating table auth_permission Creating table auth_group Creating table auth_user Creating table auth_message Creating table django_content_type Creating table django_session Creating table django_site Creating table django_admin_log Creating table django_comments Creating table django_comment_flags Creating table lifestream Creating table feeds Creating table tags Creating table items ...
How do you get at the data? どうやってデータを取れるんですか?
Queries  import  feedparser    feeds = Feed.objects. filter (feed_basic_feed=False, feed_fetchable=True) for feed in feeds:      d = feedparser. parse (feed.feed_url)‏      for entry in d[ 'entries' ]:          ...          # filters can be chained            items_count = Item.objects. filter (              Q (item_date = date_published) | \              Q (item_permalink = permalink)         ). filter (             item_feed = feed         ). count ()‏          ... jQuery ライクなセレクター構文チェーン
Queries 2 >>> item = Item.objects. get (id=1)‏ >>> item.item_feed.feed_lifestream.ls_title &quot;Ian's Lifestream&quot; 裏技で全部のオクジェクトを出してくれます。便利 便利
Saving ... i =  Item (item_feed = feed,          item_date = date_published,          item_title = entry. get ( 'title' ),          item_content = content,          item_content_type = content_type,          item_clean_content = clean_content,          item_author = entry. get ( 'author' ),          item_permalink = permalink ) i. save ()  #  を呼び出しておしまい INSERT/UPDATE を調整してくれるから簡単にできる。
Admin  モデルから、一般管理ページを生成する機能
Thank you for your listening. ご清聴ありがとうございます。

More Related Content

What's hot (19)

PDF
Web Scraping is BS
John D
 
KEY
Dig Deeper/Django C-notes
Sean O'Connor
 
ODP
Have Better Toys
apotonick
 
PDF
Mojolicious
Marcos Rebelo
 
PPTX
Twitter
Utpal Betai
 
PDF
The effective use of Django ORM
Yaroslav Muravskyi
 
PDF
เทคนิคการสืบค้น ฐานข้อมูล ProQuest Nursing & Allied Health Source
AkarimA SoommarT
 
PPT
Rails 101
The Active Network
 
PDF
Swift Summit 2017: Server Swift State of the Union
Chris Bailey
 
PDF
Csharp Intsight
Ambrosio Cardoso
 
PDF
OECD, Higher education workshop, Helsinki, 2007, Finland
Ilkka Kakko
 
PDF
The Best (and Worst) of Django
Jacob Kaplan-Moss
 
KEY
PHP for NonProgrammers (DrupalCon SF 2010)
Four Kitchens
 
PDF
"Managing API Complexity". Matthew Flaming, Temboo
Yandex
 
PDF
Cowboy development with Django
Simon Willison
 
KEY
Word Camp Fukuoka2010
YUKI YAMAGUCHI
 
PDF
tablet-coating-problems
Frenlokisan
 
PPT
Php Basic Security
mussawir20
 
Web Scraping is BS
John D
 
Dig Deeper/Django C-notes
Sean O'Connor
 
Have Better Toys
apotonick
 
Mojolicious
Marcos Rebelo
 
Twitter
Utpal Betai
 
The effective use of Django ORM
Yaroslav Muravskyi
 
เทคนิคการสืบค้น ฐานข้อมูล ProQuest Nursing & Allied Health Source
AkarimA SoommarT
 
Swift Summit 2017: Server Swift State of the Union
Chris Bailey
 
Csharp Intsight
Ambrosio Cardoso
 
OECD, Higher education workshop, Helsinki, 2007, Finland
Ilkka Kakko
 
The Best (and Worst) of Django
Jacob Kaplan-Moss
 
PHP for NonProgrammers (DrupalCon SF 2010)
Four Kitchens
 
"Managing API Complexity". Matthew Flaming, Temboo
Yandex
 
Cowboy development with Django
Simon Willison
 
Word Camp Fukuoka2010
YUKI YAMAGUCHI
 
tablet-coating-problems
Frenlokisan
 
Php Basic Security
mussawir20
 

Viewers also liked (19)

DOC
Garys Notes
angelhouse
 
ODP
Appengine ja-night-20110222
Ian Lewis
 
DOC
tests 7th
isaraul
 
PPS
商周數位學院:如何當一位好病人?
LEO FANG
 
PPT
Celery Task Queue
Ian Lewis
 
PPT
The youth and branding Africa
G. Kofi Annan
 
PPTX
Metanoia essential library skills 2014
kathy4546
 
DOCX
BDC Performance Report Template
angelhouse
 
ODP
BPStudy #40 - Google Appengine 1.4.0
Ian Lewis
 
ODP
Twisted ロングポーリング チャット サーバ
Ian Lewis
 
PDF
SCTP
guestc5d661
 
PPT
Bankruptcy And Liquidation Presentation
angelhouse
 
PPT
Key Value Storage Systems ... and Beyond ... with Python
Ian Lewis
 
PPTX
6 Digital Trends Changing Health Care / @gkofiannan
G. Kofi Annan
 
ODP
Sphinx 1.1 i18n 機能紹介
Ian Lewis
 
PPT
Every Spiritual Blessing Jan 2009
dwalkersog
 
PPTX
Metanoia literature searching 2014
kathy4546
 
PPTX
Djangoのセキュリティとその実装
aki33524
 
ODP
Djangoアプリの実践的設計手法
Ian Lewis
 
Garys Notes
angelhouse
 
Appengine ja-night-20110222
Ian Lewis
 
tests 7th
isaraul
 
商周數位學院:如何當一位好病人?
LEO FANG
 
Celery Task Queue
Ian Lewis
 
The youth and branding Africa
G. Kofi Annan
 
Metanoia essential library skills 2014
kathy4546
 
BDC Performance Report Template
angelhouse
 
BPStudy #40 - Google Appengine 1.4.0
Ian Lewis
 
Twisted ロングポーリング チャット サーバ
Ian Lewis
 
Bankruptcy And Liquidation Presentation
angelhouse
 
Key Value Storage Systems ... and Beyond ... with Python
Ian Lewis
 
6 Digital Trends Changing Health Care / @gkofiannan
G. Kofi Annan
 
Sphinx 1.1 i18n 機能紹介
Ian Lewis
 
Every Spiritual Blessing Jan 2009
dwalkersog
 
Metanoia literature searching 2014
kathy4546
 
Djangoのセキュリティとその実装
aki33524
 
Djangoアプリの実践的設計手法
Ian Lewis
 
Ad

Similar to Django O/R Mapper (20)

PPT
Django
webuploader
 
PPS
Php Security3895
Aung Khant
 
PPS
Php security3895
PrinceGuru MS
 
PPS
PHP Security
manugoel2003
 
PDF
Rugalytics | Ruby Manor Nov 2008
Rob
 
PPT
Testing persistence in PHP with DbUnit
Peter Wilcsinszky
 
PPT
Advanced and Hidden WordPress APIs
andrewnacin
 
PPT
P H P Part I I, By Kian
phelios
 
PPTX
Meetup django common_problems(1)
Eric Satterwhite
 
PDF
Intro Open Social and Dashboards
Atlassian
 
PPTX
PyCon APAC - Django Test Driven Development
Tudor Munteanu
 
KEY
Geek Moot '09 -- Smarty 101
Ted Kulp
 
PPT
MySQLConf2009: Taking ActiveRecord to the Next Level
Blythe Dunham
 
PPT
Micro-ORM Introduction - Don't overcomplicate
Kiev ALT.NET
 
ODP
Django tech-talk
dtdannen
 
PDF
Blog Hacks 2011
Yusuke Wada
 
ODP
Django Introduction Osscamp Delhi September 08 09 2007 Mir Nazim
Mir Nazim
 
PPTX
Designing CakePHP plugins for consuming APIs
Neil Crookes
 
PPT
عرض حول وردبريس
Mohammed SAHLI
 
ODP
The Basics Of Page Creation
Wildan Maulana
 
Django
webuploader
 
Php Security3895
Aung Khant
 
Php security3895
PrinceGuru MS
 
PHP Security
manugoel2003
 
Rugalytics | Ruby Manor Nov 2008
Rob
 
Testing persistence in PHP with DbUnit
Peter Wilcsinszky
 
Advanced and Hidden WordPress APIs
andrewnacin
 
P H P Part I I, By Kian
phelios
 
Meetup django common_problems(1)
Eric Satterwhite
 
Intro Open Social and Dashboards
Atlassian
 
PyCon APAC - Django Test Driven Development
Tudor Munteanu
 
Geek Moot '09 -- Smarty 101
Ted Kulp
 
MySQLConf2009: Taking ActiveRecord to the Next Level
Blythe Dunham
 
Micro-ORM Introduction - Don't overcomplicate
Kiev ALT.NET
 
Django tech-talk
dtdannen
 
Blog Hacks 2011
Yusuke Wada
 
Django Introduction Osscamp Delhi September 08 09 2007 Mir Nazim
Mir Nazim
 
Designing CakePHP plugins for consuming APIs
Neil Crookes
 
عرض حول وردبريس
Mohammed SAHLI
 
The Basics Of Page Creation
Wildan Maulana
 
Ad

Recently uploaded (20)

PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PDF
July Patch Tuesday
Ivanti
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
Python basic programing language for automation
DanialHabibi2
 
PPTX
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
PDF
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
July Patch Tuesday
Ivanti
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
Python basic programing language for automation
DanialHabibi2
 
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 

Django O/R Mapper

  • 2. I'll be giving this presentation in English. このプレゼンを英語でさせて頂きます。
  • 4. 自己紹介 名前: イアン・ルイス ( Ian Lewis )‏ 年齢: 27 歳 国籍:米国 Twitter: IanMLewis ( 80 %日本語) HP: http://www.ianlewis.org/ 所属 : BeProud   好きな物: 勉強。挑戦。 Python 。
  • 5. Ask me questions anytime. いつでも、質問をしても良い
  • 6. Why an O/R Mapper? >>> import MySQLdb >>> db=MySQLdb. connect (passwd= &quot;moonpie&quot; ,db= &quot;mydb&quot; ) >>> >>> c=db. cursor () >>> max_price=5 >>> c. execute ( &quot;&quot;&quot;SELECT name, spam, eggs, sausage FROM breakfast ... WHERE price < %s &quot;&quot;&quot; , (max_price,)) >>> c. fetchall () ( ( &quot;Spam and Sausage Lover's Plate&quot; , 5L, 1L, 8L ), ( &quot;Not So Much Spam Plate&quot; , 3L, 2L, 0L ), ( &quot;Don't Wany ANY SPAM! Plate&quot; , 0L, 4L, 3L ) ) >>> c.executemany( ... &quot;&quot;&quot;INSERT INTO breakfast (name, spam, eggs, sausage, price) ... VALUES ( %s , %s , %s , %s , %s )&quot;&quot;&quot; , ... [ ... ( &quot;Spam and Sausage Lover's Plate&quot; , 5, 1, 8, 7.95 ), ... ( &quot;Not So Much Spam Plate&quot; , 3, 2, 0, 3.95 ), ... ( &quot;Don't Wany ANY SPAM! Plate&quot; , 0, 4, 3, 5.95 ) ... ] )‏
  • 8. Models Objects Database
  • 9. Ok, Let's make a model さて、モデルを作りましょう
  • 10. Models class Feed (models.Model):     '''A RSS/Atom feed.'''     feed_lifestream = models. ForeignKey (Lifestream)         feed_name = models. CharField ( &quot;Feed Name&quot; , max_length=255)     feed_url = models. URLField ( &quot;Feed Url&quot; , verify_exists=True, max_length=1000)     feed_domain = models. CharField ( &quot;Feed Domain&quot; , max_length=255)     feed_fetchable = models. BooleanField ( &quot;Is Feed Fetchable?&quot; , default=True)       # Used for feeds that allow users to directly add to the lifestream.     feed_basic_feed = models. BooleanField ( &quot;Is Basic Feed?&quot; , default=False)       objects = FeedManager ()       def __unicode__ (self):         return self.feed_name         class Meta :         db_table= &quot;feeds&quot;
  • 11. Relationships class Item (models.Model):   '''A feed item'''   # One to many relationship   item_feed = models. ForeignKey ( &quot;Item Feed&quot; , Feed)   item_date = models. DateTimeField ( &quot;Publish Date&quot; )   item_title = models. CharField ( &quot;Title&quot; , max_length=255)   item_content = models. TextField ( &quot;Item Content&quot; , null=True, blank=True)   item_permalink = models. UrlField ( &quot;Permalink&quot; , max_length=1000)‏   # Many to Many relationship   item_tags = models. ManyToManyField (Tag, null=True, blank=True, db_table=&quot;item_tags&quot;)‏   ...
  • 12. Database Sync [email_address] ~/src/dlife/dlife $ python manage.py syncdb Creating table auth_permission Creating table auth_group Creating table auth_user Creating table auth_message Creating table django_content_type Creating table django_session Creating table django_site Creating table django_admin_log Creating table django_comments Creating table django_comment_flags Creating table lifestream Creating table feeds Creating table tags Creating table items ...
  • 13. How do you get at the data? どうやってデータを取れるんですか?
  • 14. Queries import feedparser   feeds = Feed.objects. filter (feed_basic_feed=False, feed_fetchable=True) for feed in feeds:     d = feedparser. parse (feed.feed_url)‏     for entry in d[ 'entries' ]:         ...         # filters can be chained         items_count = Item.objects. filter (             Q (item_date = date_published) | \             Q (item_permalink = permalink)         ). filter (             item_feed = feed         ). count ()‏         ... jQuery ライクなセレクター構文チェーン
  • 15. Queries 2 >>> item = Item.objects. get (id=1)‏ >>> item.item_feed.feed_lifestream.ls_title &quot;Ian's Lifestream&quot; 裏技で全部のオクジェクトを出してくれます。便利 便利
  • 16. Saving ... i = Item (item_feed = feed,          item_date = date_published,          item_title = entry. get ( 'title' ),          item_content = content,          item_content_type = content_type,          item_clean_content = clean_content,          item_author = entry. get ( 'author' ),          item_permalink = permalink ) i. save () # を呼び出しておしまい INSERT/UPDATE を調整してくれるから簡単にできる。
  • 18. Thank you for your listening. ご清聴ありがとうございます。