Your SlideShare is downloading. ×
0
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Meetup django common_problems(1)
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Meetup django common_problems(1)

2,591

Published on

Slides from 5/11/2011 Milwaukee Django User Group Meetup

Slides from 5/11/2011 Milwaukee Django User Group Meetup

Published in: Technology, Art & Photos
0 Comments
5 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,591
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
43
Comments
0
Likes
5
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  1. Who is this fool?!<br />A little about me<br />
  2. Graphic Art<br />Photography<br />Web Design<br />Django<br />VFX<br />JavaScript<br />Print Design<br />Software<br />Digital Media<br />CSS<br />Python<br />Flash / Flex<br />
  3. PERL & JavaScript<br />
  4. Django = HotPileOfAwesome( yes=True )<br />Django.build_web_app( fast=True )<br />
  5. Django.make_an_app()<br />>>> True<br />Django.log_in_user()<br />>>> True<br />Django.comment_on_my_model()<br />>>> True<br />Django.message_my_user(user='myuser')<br />>>> True<br />Django.send_emails( emails=['me@mail.com'] )<br />>>> True<br />Django.do_complex_SQL( please=True )<br />>>> No Problem!<br />
  6. Django.make_a_thumbnail()<br />>>> Thumbnail?<br />Django.send_text_message()<br />>>> Email Exception: no such thing<br />Django.search_all_my_stuff()<br />>>> WTF?<br />Django.get_data_in_under_75_queries()<br />>>> Whoa...<br />Django.alter_table(model='MyModel')<br />>>> Let's not get crazy<br />Django.be_restful( now=True )<br />>>> you meanrequest.POST<br />
  7. I've Got an <br />app for that!<br />
  8. Searching<br />
  9. Searching<br />Find Stuff - Fast<br />
  10. Searching<br />Find Stuff - Fast<br />( without crushing my DB )<br />
  11. Haystack<br />haystacksearch.org<br />Djapian<br />code.google.com/p/djapian/<br />Sphinx<br />django-sphinx ( github )<br />
  12. Django<br />MyModel.objects.filter( text__icontains='word' )OR MyModel.objects.filter( text__search='word' )<br />Problems:<br /><ul><li>single model
  13. slow
  14. mysql
  15. manual DB configs</li></li></ul><li>Haystack<br />classPostIndex( SearchIndex ): <br />body = CharField(document = True, model_attr = 'body') <br />title = CharField( model_attr = 'title') <br />author = CharField( model_attr = 'author__get_full_name')<br />text = CharField( use_template = True ) <br />defget_queryset( self ): <br />return Post.objects.all() <br />defprepare_url( self, obj ): <br />return obj.get_absolute_url() <br />site.register(Post, PostIndex) <br />
  16. Haystack<br />SearchQuerySet()<br />.filter( <br />SQ(field=True) <br />| SQ(field__relation="something") <br />~SQ(field=False) <br />)<br />>>> [ <SearchResult>, <SearchResult>, <SearchResult> ]<br />
  17. Xapian<br />classArticleIndexer( Indexer ):<br />fields = ['title','body']<br />tags = [<br />('title','title', 3),<br />('body', 'as_plain_text', 1)<br />]<br />space.add_index(Article, ArticleIndexer, attach_as='indexer')<br />
  18. Xapian<br />fromdjapian.indexer import CompositeIndexer<br />flags = xapian.QueryParser.FLAG_PARTIAL| <br />xapian.QueryParser.FLAG_WILDCARD<br />indexers = [ Model_1.indexer, Model_2.indexer ]<br />comp = CompositeIndexer( *indexers )<br />s = comp.search( `a phrase` ).flags( flags )<br />>>> [ <hit:score=100>,<hit:score=98> ]<br />$ s[0].instance<br />>>> <ModelInstance:Model><br />
  19. Haystack<br />Xapian<br />Index files<br />Class Based Index<br />Customize Text For Indexing<br />Link to Indexed Object<br />Index Fields, Methods & Relations<br />Stemming, Facetting, Highlighting, Spelling<br /><ul><li>Pluggable Architecture
  20. Whole Word Matching
  21. Loads all indexers
  22. Multiple Index Hooks
  23. Stored fields
  24. Django-like Syntax
  25. Templates & Tags
  26. Views, Forms & Fields
  27. Wildcard Matching
  28. Partial word matching
  29. Doesn't Load All indexers
  30. Interactive shell
  31. Close to the metal ( Control )
  32. Watches Models for changes
  33. Pre-index Filtering</li></li></ul><li>REST API<br />
  34. REST API<br />Exposing Your Data<br />
  35. REST API<br />Exposing Your Data<br />( In a meaningful way )<br />
  36. Django<br />defview_func( reqeuest, *args, **kwargs): request.GET request.POST request.FILES<br />Problems:<br /><ul><li>PUT & DELETE not translated
  37. Can't restrict access based on HTTP methods
  38. Serialization is left up to you
  39. Manual auth
  40. Tons of URLs</li></li></ul><li>PISTON<br />bitbucket.org/jespern/django-piston<br />TASTYPIE<br />toastdriven.github.com/django-tastypie/<br />
  41. Piston<br />classMyHandler( BaseHandler ): <br />methods_allowed =( 'GET', 'PUT') <br />model = MyModel <br />classMyOtherHandler( BaseHandler ): <br />methods_allowed =( 'GET', 'PUT') <br />model = MyOtherModel<br />fields = ('title','content',('author',('username',) ) )<br />exclude = ('id', re.compile(r'^private_'))<br />defread( self, request):<br />return [ x for x in MyOtherModel.objects.select_related() ]<br />defupdate( self, request ):<br />...<br />
  42. Tastypie<br />classMyResource( ModelResource ):<br />fk_field = fields.ForiegnKey( OtherResource, 'fk_field' ) <br />classMeta:<br />authentication = ApiKeyAuthentication() <br />queryset = MyModel.object.all()<br />resource_name = 'resource'<br />fields = ['title', 'content', ]<br />allowed_methods = [ 'get' ]<br />filtering = {<br />'somfield': ('exact', 'startswith')<br />}<br />defdehydrate_FOO( self, bundle ):<br />return bundle.data[ 'FOO' ] = 'What I want'<br />
  43. Tastypie - Client Side<br />newRequest.JSONP({<br />url:'http://www.yoursite.com/api/resource'<br />,method:'get'<br />,data:{<br />username:'billyblanks'<br />,api_key:'5eb63bbbe01eeed093cb22bb8f5acdc3'<br />,title__startswith:"Hello World"<br />}<br />,onSuccess: function( data ){<br />console.info( data.meta );<br />console.log( data.objects ):<br />}).send();<br />http://www.yoursite.com/api/resource/1<br />http://www.yoursite.com/api/resource/set/1;5<br />http://www.yoursite.com/api/resource/?format=xml<br />
  44. PISTON<br />TASTYPIE<br />Multiple Formats<br />Throttling<br />All HTTP Methods<br />Authentication<br />Arbitrary Data Resources<br />Highly Configurable<br /><ul><li>Django-like
  45. Built in fields
  46. Auto Meta Data
  47. Resource URIs
  48. ORM ablities ( client )
  49. API Key Auth
  50. Object Caching ( backends )
  51. De / Re hydrations hooks
  52. Validation Via Forms
  53. Deep ORM Ties
  54. Data Streaming
  55. OAuth / contrib Auth
  56. URI Templates
  57. Auto API Docs</li></li></ul><li>READY IN MINUTES<br />
  58. DATABASE<br />
  59. DJANGO-SOUTH<br />south.aeracode.org<br />QUERYSET-TRANSFORM<br />github.com/jbalogh/django-queryset-transform<br />DJANGO-SELECTREVERSE<br />code.google.com/p/django-selectreverse<br />
  60. SOUTH<br />
  61. SOUTH<br />Database Migrations<br />
  62. DJANGO<br />$ python manage.py syncdb<br />
  63. DJANGO<br />$ python manage.py syncdb<br />>>> You have a new Database!<br />
  64. DJANGO<br />classMyModel( models.Model):<br />relation = models.ForiegnKey( Model2 )<br />
  65. DJANGO<br />classMyModel( models.Model ):<br />relation = models.ForiegnKey( Model2 )<br />classMyModel( models.Model ):<br />relation = models.ManyToMany( Model2 )<br />
  66. DJANGO<br />$ python manage.py syncdb<br />
  67. DJANGO<br />$ python manage.py syncdb<br />>>> Sucks to be you!<br />
  68. WTF?!<br />
  69. DJANGO<br />$ python manage.py syncdb<br />>>> Sucks to be you!<br />Problem:<br /><ul><li>syncdb doesn't really sync your db. Migrations must be done manually.For everyedatabase / set up.</li></li></ul><li>SOUTH<br /><ul><li>Migrations are a set of sequential .py filesdb agnosticHandle most relation typesRolls migrations forward Handles Dependancies / Reverse DependanciesCan convert existing apps Overrides existing syncdb command</li></li></ul><li>DJANGO<br />classMyModel( models.Model ):<br />relation = models.ForiegnKey( Model2 )<br />classMyModel( models.Model ):<br />relation = models.ManyToMany( Model2 )<br />
  70. DJANGO<br />classMyModel( models.Model ):<br />relation = models.ForiegnKey( Model2 )<br />classMyModel( models.Model ):<br />relation = models.ManyToMany( Model2 )<br />
  71. SOUTH<br />$ python manage.py schemamigration <yourapp><br />>>> Sweet, run migrate<br />
  72. SOUTH<br />$ python manage.py migrate <yourapp><br />>>> Done.<br />
  73. SOUTH<br />
  74. QUERYSET-TRANSFORM<br />github.com/jbalogh/django-queryset-transform<br />( n + 1 )<br />
  75. QUERYSET-TRANSFORM<br />{%for object in object_list %}<br />{%for object in object.things.all %}<br />{%if object.relation %}<br />{{ object.relation.field.text }}<br />{%else%}<br />{{ object.other_relation }}<br />{%endif%}<br />{%endfor%}<br />{%empty%}<br />no soup for you<br />{%endfor%}<br />
  76. QUERYSET-TRANSFORM<br />deflookup_tags(item_qs):<br />item_pks = [item.pk for item in item_qs]<br />m2mfield = Item._meta.get_field_by_name('tags')[0]<br />tags_for_item = <br />Tag.objects.filter(<br />item__in = item_pks)<br />.extra(select = {'item_id': '%s.%s' % (<br />m2mfield.m2m_db_table(),<br />m2mfield.m2m_column_name()<br />) <br />}) <br />tag_dict = {}<br />for tag in tags_for_item:<br />tag_dict.setdefault(tag.item_id, []).append(tag)<br />for item in item_qs:<br />item.fetched_tags = tag_dict.get(item.pk, [])<br />
  77. QUERYSET-TRANSFORM<br />qs = Item.objects.filter(<br />name__contains = 'e'<br />).transform(lookup_tags)<br />
  78. QUERYSET-TRANSFORM<br />from django.db import connection<br />len( connection.queries )<br />>>> 2<br />
  79. DJANGO-SELECTREVERSE<br />code.google.com/p/django-selectreverse<br />
  80. DJANGO-SELECTREVERSE<br />Tries prefetching on reverse relations<br />model_instance.other_model_set.all()<br />
  81. CONTENT MANAGEMENT<br />
  82. DJANGO-CMS<br />www.django-cms.org<br />WEBCUBE-CMS<br />www.webcubecms.com<br />SATCHMO<br />www.satchmoproject.com<br />
  83. WEBCUBE-CMS<br />
  84. WEBCUBE-CMS<br />Feature Complete<br />
  85. WEBCUBE-CMS<br />Feature Complete<br />Robust & Flexible<br />
  86. WEBCUBE-CMS<br />Feature Complete<br />Robust & Flexible<br />( Commercial License )<br />
  87. $12,000<br />
  88. $12,000<br />
  89. + $300 / mo<br />
  90. WTF?!<br />
  91. DJANGO-CMS<br />
  92. PRO<br />CON<br /><ul><li>Heavily Customised Admin
  93. Plugin Support
  94. Template Switching
  95. Menu Control
  96. Translations
  97. Front-End Editing ( latest )
  98. Moderation
  99. Template Tags
  100. Lots of settings
  101. Lots Of Settings ( again )
  102. Another Learning Curve
  103. Plone Paradox
  104. Plugins a little wonky</li></li></ul><li>SATCHMO<br />
  105. SATCHMO<br />E-Commerce-y CMS<br />
  106. Django Admin<br />
  107. DJANGO-GRAPPELLI<br />code.google.com/p/django-grappelli<br />DJANGO-FILEBROWSE<br />code.google.com/p/django-filebrowser<br />DJANGO-ADMIN TOOLS<br />bitbucket.org/izi/django-admin-tools<br />
  108. GRAPPELLI<br />
  109. GRAPPELLI<br />
  110. GRAPPELLI<br />
  111. FILEBROWSER<br />
  112. FILEBROWSER<br />
  113. FILEBROWSER<br />
  114. FILEBROWSER<br />
  115. ADMIN TOOLS<br />
  116. ADMIN TOOLS<br />
  117. ADMIN TOOLS<br />
  118. Image Management<br />
  119. DJANGO-IMAGEKIT<br />bitbucket.org/jdriscoll/django-imagekit<br />DJANGO-PHOTOLOGUE<br />code.google.com/p/django-photologue<br />SORL-THUMBNAIL<br />thumbnail.sorl.net/<br />
  120. DJANGO<br />classMyModel( models.Model ):<br />image = models.ImageField(upload_to='/' )<br />
  121. DJANGO<br />classMyModel( models.Model ):<br />image = models.ImageField( upload_to='/' )<br />thumb = models.ImageField( upload_to='/' )<br />
  122. DJANGO<br />classMyModel( models.Model ):<br />image = models.ImageField( upload_to='/' )<br />thumb = models.ImageField( upload_to='/' )<br />>>> MyModel.objects.get(pk=1)<br />>>> MyModel.objects.image.url<br />>>> MyModel.objects.thumb.url<br />
  123. ImageField<br />
  124. ImageField<br />It Kinda Sucks<br />
  125. IMAGEKIT<br />Evolution Of Photologue<br />
  126. IMAGEKIT<br />classPhoto( ImageModel ):<br />name = models.CharField(max_length=100)<br />image = models.ImageField(upload_to='photos') <br />views = models.PositiveIntegerField(default=0)<br />classIKOptions:<br />#define the ImageKit options<br />spec_module = 'myapp.specs'<br />cache_dir = 'photos'<br />image_field = 'image'<br />save_count_as = 'views'<br />
  127. IMAGEKIT<br />classResizeThumb( processors.Resize ):<br />width = 100<br />height = 75<br />crop = True<br />classResizeDisplay( processors.Resize ):<br />width = 600<br /># now we can define our thumbnail spec<br />classThumbnail( ImageSpec ):<br />access_as = 'thumbnail_image'<br />pre_cache = True<br />processors = [ ResizeThumb ]<br />classDisplay( ImageSpec ):<br />increment_count = True<br />processors = [ ResizeDisplay ]<br />
  128. IMAGEKIT<br />$ photo = Photo.objects.get( pk =1 )<br />$ photo.display.url<br />>>> u'/path/to/media/photo_display.jpg'<br />$ photo.thumbnail.width<br />>>> 100<br />
  129. IMAGEKIT<br />PHOTLOGUE<br />Caching<br />Template Friendly<br />Highly Configurable<br />Management Commands<br /><ul><li>Only 1 Model
  130. DB Friendly
  131. Format Adjustment
  132. Color Adjustment
  133. Transposing
  134. Galleries out of the box
  135. Bulk Upload
  136. Admin Integration
  137. Pre-cache command
  138. Very DB Dependant
  139. 4 Models ( 2 Solid )
  140. Templates / Views / Urls
  141. Exif Support</li></li></ul><li>EXIF TAGS<br />ISSUE 153<br />( shameless plug )<br />
  142. IMAGEKIT<br />PHOTLOGUE<br />Caching<br />Template Friendly<br />Highly Configurable<br />Management Commands<br /><ul><li>Only 1 Model
  143. DB Friendly
  144. Format Adjustment
  145. Color Adjustment
  146. Transposing
  147. Galleries out of the box
  148. Bulk Upload
  149. Admin Integration
  150. Pre-cache command
  151. Very DB Dependant
  152. 4 Models ( 2 Solid )
  153. Exif Support</li></ul>Beware of View Counts<br />
  154. ImageField<br />
  155. ImageField<br />It's Kinda Messy<br />
  156. SORL<br />
  157. SORL<br />from sorl.thumbnail import ImageField<br />classMyModel( models.Model ):<br />iamge = ImageField( upload_to="/folder" )<br />
  158. SORL<br />{% load thumbnail %}<br />{%thumbnail obj.image "1000x600" crop='top' as im %}<br /><img src="{{ im.url }}" /><br />{%endthumbnail%}<br />
  159. MESSAGING<br />
  160. User - to - User<br />Messaging<br />
  161. DJANGO-POSTMAN<br />bitbucket.org/psam/django-postman<br />DJANGO-MESSAGES<br />code.google.com/p/django-messages<br />DJANGO-SMS<br />code.google.com/p/django-sms<br />
  162. DJANGO-SMS<br />
  163. DJANGO-SMS<br />User Enters Phone #<br />User Selects Carrier<br />
  164. THATS IT<br />
  165. FREE<br />
  166. UTILS<br />
  167. DJANGO-EXTENSIONS<br />github.com/django-extensions/django-extensions<br />DEBUG-TOOLBAR<br />github.com/robhudson/django-debug-toolbar<br />DJANGO-MAINTENANCEMODE<br />pypi.python.org/pypi/django-maintenancemode<br />DJANGO-PAGINATION<br />github.com/ericflo/django-pagination<br />DJANGO-GUARDIAN<br />github.com/lukaszb/django-guardian<br />HOTSAUCE<br />( self plug )<br />
  168. DJANGO-EXTENSIONS<br />21 Commands<br />4 Fields<br />2 Models<br />1 Admin Extension ( FK AutoComplete )<br />$ python manage.py dumpscript<br />>>> your_app.py<br />$ python manage.py runscript<br />>>> your_app.pyc<br />$ python manage.py runserver_plus<br />>>> Debugger baked right in<br />$ python manage.py shell_plus<br />>>> AutoLoad Models<br />$ python manage.py show_urls<br />>>> /your/endpoint/:idproject.app.views.view_func<br />
  169. RUNSERVER_PLUS<br />
  170. DEBUG TOOLBAR<br />
  171. DEBUG TOOLBAR<br />
  172. MAINTENANCEMODE<br />
  173. MAINTENANCEMODE<br />MAINTENANCE_MODE = True<br />
  174. MAINTENANCEMODE<br />MAINTENANCE_MODE = True<br />
  175. MAINTENANCEMODE<br />MAINTENANCE_MODE = True<br />
  176. HOTSAUCE<br />
  177. HOTSAUCE<br />I Put That $*!T On Everything<br />
  178. HOTSAUCE<br />
  179. HOTSAUCE<br />
  180. HOTSAUCE<br />QueueItem<br />ChangeSet<br />title<br />content<br />Model A<br />ChangeSet<br />title<br />content<br />ChangeSet<br />Model A<br />ChangeSet<br />title<br />content<br />
  181. HOTSAUCE<br />

×