Pro Yearly is on sale from $80 to $50! »

Writing a Django e-commerce framework

Writing a Django e-commerce framework

Django is well-suited for e-commerce, and there are currently several nascent django e-commerce frameworks in development. This talk is about the development of django-oscar, a framework designed to leverage Django's core functionality to allow domain-driven e-commerce applications to be built. This is a very powerful approach.

Writing django apps which are flexible enough to be adapted to a wide variety of
scenarios is a non-trivial problem which will be explored. The talk will also
cover a range of e-commerce best practices and how they can be implemented in
Django.

52d39c7b27386ca98bc016119d95b8b8?s=128

David Winterbottom

March 02, 2012
Tweet

Transcript

  1. Writing a Django e-commerce framework David Winterbottom @codeinthehole

  2. Synopsis • Background / challenges • Why django / python

    • Customising django apps • E-commerce tips
  3. None
  4. None
  5. None
  6. Background

  7. • 5 years of e-commerce projects • PHP / Python

    / Django • Lots of war stories
  8. Books

  9. Bookshop domain • Millions of products • ISBNs, BIC categories,

    authors, publishers • Automated feed-driven processing • Catalogue • Stock • Rich data
  10. Two tier structure • Application tier - serves HTTP requests

    • Processing tier • Download and import feeds • Data cleaning and processing
  11. More books

  12. Different... • Fulfilment partners • Stock logic • Payment partners

    • Multiple payment sources • Complicated offers • eBooks!
  13. PHP framework • Customisation via include path overrides • Lots

    of duplication • Hard to upgrade • Not-invented-here syndrome
  14. Nailvarnish

  15. T-shirts

  16. Digital music

  17. Bar equipment

  18. New requirements • Product variations - colours, sizes etc •

    New fulfilment processes • Pricing models
  19. B2B • Sales reps • Tax rules • Managed budgets

    • Integration with “enterprise” software
  20. • Original assumptions all broken • Domains vary wildly •

    Lots of work-arounds
  21. None
  22. Requirements • Agnostic - few assumptions as possible • Models

    domain • without duplication • without too much meta-data
  23. EAV ENTITY ATTRIBUTE VALUE Product Weight 150 Order Cost centre

    ZPAN
  24. None
  25. None
  26. • Leather gloves

  27. Bendy bits

  28. Taxonomy

  29. Stock

  30. Shipping

  31. Payment

  32. and also...

  33. None
  34. Nothing is sacred

  35. None
  36. None
  37. django-oscar • Django 1.3 • Experience of last 5 years

    baked into models • Lean core • Different customisation path
  38. None
  39. Lots of others • Satchmo • Lightning-Fast-Shop • Satchless •

    Django-shop • Plata, Mamona, Cartridge, ... • http://djangopackages.com/grids/g/ecommerce/
  40. None
  41. Decimals

  42. None
  43. None
  44. None
  45. kwargs

  46. Shipping calculator

  47. PHP

  48. None
  49. None
  50. None
  51. None
  52. None
  53. None
  54. None
  55. Python

  56. None
  57. None
  58. Web framework • Well-thought out structure • Templating, HTTP, caching,

    ... • Good test support • Security • Class-based views
  59. Models • Models drive the design • Capture domain logic

    • Foundation for rest of application
  60. Eco-system • Haystack (search) • South (database migrations) • Celery

    (job queue) • Internal libraries
  61. None
  62. Customisation

  63. Techniques

  64. DEBUG = True settings.py

  65. AUTH_PROFILE_MODULE = ‘customer.Profile’ settings.py

  66. Key idea • Having the same name/identifier as your parent

    • Subclass and override
  67. Templates

  68. None
  69. None
  70. None
  71. None
  72. Django looks here first

  73. Views

  74. Oscar default

  75. urls.py

  76. oscar/app.py

  77. oscar/core/app.py

  78. oscar/apps/checkout/app.py

  79. Oscar project

  80. Replace application urls.py

  81. myproject/app.py Use different app instance

  82. myproject/checkout/app.py Use different view classes

  83. myproject/checkout/views.py Override and extend method

  84. Models

  85. Oscar default

  86. settings.py

  87. abstract_models.py

  88. models.py

  89. Oscar project

  90. replaces oscar app settings.py same ‘app label’

  91. add custom fields myproject/voucher/models.py import remaining models

  92. templatetags management commands fixtures settings.py

  93. Classes

  94. model name ‘app label’

  95. module path class name

  96. use same class name as in core

  97. Recap • Bit of a work-around... • ...but works well

    • Applicable to other django libraries
  98. Best practices

  99. Log everything ...except bankcard details.

  100. Audit models

  101. None
  102. Monitor everything watch high and low thresholds

  103. SOA • Services make your life easier • Keep a

    layer in front of your models • Facade design pattern
  104. View

  105. View Models Database Load business objects

  106. View Service Models Database Load business objects Business logic here

  107. View Service Models Database Load business objects Business logic here

  108. View Service Models Database Load business objects Business logic here

  109. Rules of thumb • Keep views lean • Business logic

    in: • Models • Services • Validation logic in forms
  110. None
  111. Danger

  112. Domain pollution • When integrating with a 3rd party... •

    they will try and push their shortcomings into your platform
  113. None
  114. Anti-corruption layer Your platform Their platform Anti-corruption layer

  115. Summary • Django e-commerce is an emerging force • Customising

    django apps isn’t easy • Oscar’s future: • NoSQL • Table inheritance
  116. Image credits Books: http://www.flickr.com/photos/th3ph17/3091294342/ More books: http://www.flickr.com/photos/cheryl-j/3965942320/ Nail varnish: http://www.flickr.com/photos/greenzowie/5451402463/

    Leather gloves: http://www.flickr.com/photos/theopenseas/175598276/ Lego shipping: http://www.flickr.com/photos/lydiashiningbrightly/5356210011/ Rubber gloves: http://www.flickr.com/photos/recyclethis/139373445/ Warehouse: http://www.flickr.com/photos/23748404@N00/15648677/ Taxonomy: http://www.flickr.com/photos/kqedquest/831547339/ T-shirts: http://www.flickr.com/photos/blazerman/177165473/