Upload
dudarev
View
9.916
Download
1
Embed Size (px)
DESCRIPTION
Presentation for #donetskpy meetup on February 18th, 2012.
Citation preview
Django with Mongo usingMongoengine
Artem Dudarev#donetskpy, #cncdnua, February 2012
Other ways to use Mongo with DjangoWhich Python API should be used with Mongo DB andDjango?
• PyMongo--
• Mongoengine--
• Django MongoDB Engine• MongoDB backend for Django-nonrel
Django
DjangoThe Web framework for perfectionists with deadlines.Using Django
• Disqus• Many newspapers: Washington Post, Guardian,
Lawrence.com.In Donetsk
• Steelkiwi• MLSDev
MongoMongo (from "humongous") is a scalable,high-performance, open source NoSQL database.Using Mongo
• Foursquare• Catch
In Donetsk• ?
MongoengineMongoEngine is a Document-Object Mapper (think ORM,but for document databases) for working with MongoDBfrom Python.
Mongoengine examplefrom mongoengine import (Document, EmbeddedDocument, ListField, StringField, IntField)
class Metadata(EmbeddedDocument): tags = ListField(StringField()) revisions = ListField(IntField())
class WikiPage(Document): title = StringField(required=True) text = StringField() metadata = EmbeddedDocumentField(Metadata)
Mongoengine example (cont.)>>> page.title = “Hello, World!”>>> for page in WikiPage.objects:>>> print page.title
«Делайте велосипеды, но то так, чтобы хотелось на них ездить.»
— Игорь Давыденко, #kyivpy #5
Tumblr• http://wearethe99percent.tumblr.com/• http://dearphotograph.com/• http://stockingisthenewplanking.com/
• http://dudarev.tumblr.com/
Tumblr (cont.)http://mashable.com/2011/11/14/tumblr-infographic/
• 35M tumblogs• 45% photos• Top 5 tags: GIF, LOL, Fashion, Art, Vintage• 218% growth (from June to June)• $800M valuation
Mumblr• Harry Marr - developer of Mongoengine• Mumblr - Tumblr clone
Starting with Python (virtualenv, pip)git clone https://github.com/hmarr/django-mumblr.git mumblrcd mumblrvirtualenv .source bin/activatepip install -r requirements.txtcd example
Mumblr (starting Mongo)http://www.mongodb.org/display/DOCS/Quickstart+Unixcurl http://downloads.mongodb.org/linux...tgz > mongo.tgztar xzf mongo.tgzsudo chown `id -u` /data/dbsudo chown `id -u` /data/db/*./mongodb-linux-i686-2.0.2/bin/mongod
./mongodb-linux-i686-2.0.2/bin/mongouse mumblr-exampledb.dropDatabase()
Mumblr (adding user)ls mumblr/management/commands/python manage.py addusepython manage.py runserver
Points• Django is an excellent framework for not too
complicated sites• MongoDB is #1 NoSQL database - try it• Djangists may find Mongoengine convenient• Do reinvent the wheel• Make it easy for others to start using it
CreditsLogos
• Django• Mongo• Mongoengine
Comics• How to Write a CV• The Hard Life Of A NoSQL Coder
rst2pdf• rst2pdf• style by Alexis Métaireau was partially used