SlideShare une entreprise Scribd logo
1  sur  28
Dynamic Models
in Django
Juergen Schackmann
j.schackmann@reliatec.de
© Juergen Schackmann 2013 2/28
Me
▸ Python & Django since 4 years
▸ reliatec.de since 3 months
▸ Django Web Applications
▸ Focus: EDC systems for clinical studies & Telemonitoring
© Juergen Schackmann 2013 3/28
Objective
▸ Why do do we care about Django Dynamic Models?
▸ Why do we have to talk about them?
▸ What should we do about them?
Static vs Dynamic Models
© Juergen Schackmann 2013 5/28
Models in a Django project
Phase1:
Code Development
Models and model
attributes are defined by
implementing those with
Python code
Phase 2:
Deployment
Underlying database tables
and columns are created by
running “syncdb” command
Phase 3:
Runtime
Models / DB Tables are
populated with content as
part of the user
interactions
© Juergen Schackmann 2013 6/28
Problem?
There is no way to adapt the Django Models at runtime based on
user interactions
▸ Django Models are defined and implemented during
development phase
▸ Django Models are expected to be static after deployment
▸ Django DB Backends only fully support SQL databases, i.e. a
schema is required
▸ DB specific solutions limit adoption rate of any reusable App
Use Cases for Dynamic
Models
© Juergen Schackmann 2013 8/28
Custom Content Types for a CMS*
* system: dotCms (Java); source: http://dotcms.com/
© Juergen Schackmann 2013 9/28
Customized Products for an Ecommerce Shop*
* system: Magento (PHP); source: averybrandandprint.co.uk
© Juergen Schackmann 2013 10/28
Clinical Research Forms*
* system: OpenClinica (Java); source: openclinica.com
© Juergen Schackmann 2013 11/28
Problem? Which Problem?
▸ Models / Content Types are domain or site specific
▸ Neither realistic nor efficient to implement all thinkable content
types into a software product
▸ Configuration by subject-matter experts is better, than code
customization by developers
▸ Dynamic Models reduce the number of deployment cycles
Evaluation of
Patterns & Apps
© Juergen Schackmann 2013 13/28
As a User, I ...
▸ want to maintain my dynamic models easily without
understanding any Django Model details
▸ want extend existing (static) models without thinking about
static and dynamic parts
▸ do not want to think about performance, when creating my
custom fields
▸ I want to be able to query/search for certain information
seamlessly over static and dynamic models
© Juergen Schackmann 2013 14/28
As a developer, I ...
▸ want my dynamic models to be integrated with Django Standard
Tools (admin, migrations, reversion) out of the box
▸ want to apply the same API that I use for the static models
▸ do not want to use or be limited to specific databases, but use
the standard Django backends
▸ want to have a customizable front-end for my users to manage
the dynamic models
© Juergen Schackmann 2013 15/28
Evaluation Criteria
▸ Performance
▸ “Querybility”
▸ Django Standard Tools Integration (Admin, Cache, ...)
▸ Supported Backend
▸ Complexity/ Maintainability
© Juergen Schackmann 2013 16/28
Entity Attribute Value (EAV)
Transform your table columns into table rows
Attribute 1 Attribute 2 Attribute n
Table
Attribute
Name
Attribute
Value
Attribute
TableTable has1 n
© Juergen Schackmann 2013 17/28
EAV Django Apps
▸ bitbucket.org/neithere/eav-django/
▸ github.com/mvpdev/django-eav
© Juergen Schackmann 2013 18/28
Serialized Dictionary
Transform your table columns into pickeld or jsoned dictionaries
Attribute 1 Attribute 2 Attribute n
Table
Dictionary
String
Attributes
{“attribute1”:”a”, “attribute2”: 5, “attribute3”:[1,2] }
© Juergen Schackmann 2013 19/28
Serialized Dictionary Django Apps
Fields
▸ bitbucket.org/schinckel/django-jsonfield/
▸ github.com/bradjasper/django-jsonfield
▸ github.com/derek-schaefer/django-json-field
▸ github.com/shrubberysoft/django-picklefield
App
▸ github.com/dobarkod/django-dynamic-model
© Juergen Schackmann 2013 20/28
Runtime Schema Updates
Update Django models and database schema at runtime using
▸ syncdb functionality
▸ South functionality
▸ eventually: Andrew Godwin's “Schema Migrations for Django”
© Juergen Schackmann 2013 21/28
Runtime Schema Update Django Apps
Update Django models and database schema at runtime using
▸ Syncdb
▸ bitbucket.org/mhall119/dynamo/overview
▸ South
▸ github.com/willhardy/dynamic-models
▸ github.com/willhardy/django-dymo
▸ bitbucket.org/schacki/django-dynamo
▸ github.com/charettes/django-mutant
▸ Schema Migrations
▸ github.com/charettes/django-mutant
© Juergen Schackmann 2013 22/28
Database specific solutions
Hstore
▸ github.com/jordanm/django-hstore
▸ postgresql.org/docs/9.0/static/hstore.html
No SQL
▸ github.com/django-nonrel
▸ github.com/pydanny/django-mongonaut
© Juergen Schackmann 2013 23/28
Summary
EAV Serialization Schema Updates
Performance   
Querybility   
Django Standard
Tools
 / 
Supported
Backend
  
Complexity/
Maintainability
  
© Juergen Schackmann 2013 24/28
Schema Update most powerful, but ...
▸ Name clashes between developer models and dynamic models
(especially with schema migrations)
▸ Multiple Users updating the same model (possibly even
conflicting)
▸ Orphan database elements
▸ Dynamic Model loading at startup
▸ How to find/inject dynamic models into views and templates
Components of a
Dynamic Model App
© Juergen Schackmann 2013 26/28
Must have components of a Dynamic Model
Application
▸ Meta Model Front End to let users maintain their meta models
▸ Meta Model Representation to store the meta model information
▸ Meta Model Analyzer to detect changes that require some further
actions (for schema, admin or model)
▸ Schema Sync Manager to update and sync the database schema
▸ Admin Sync Manager to update and sync the Django admin
▸ Model/Cache Sync Manager to update and sync the Django models
and model cache
© Juergen Schackmann 2013 27/28
More resources on dynamic models
▸ code.djangoproject.com/wiki/DynamicModels
▸ djangopackages.com/grids/g/forms/
▸ stackoverflow.com/questions/7933596/django-dynamic-model-
fields/7934577
Thank you very much!
Questions please?

Contenu connexe

Tendances

Social Media Marketing Proposal (1).pdf
Social Media Marketing Proposal (1).pdfSocial Media Marketing Proposal (1).pdf
Social Media Marketing Proposal (1).pdf
Ken Khan
 
Keyword Research | Keyword Research For SEO 2019 | SEO Tutorial For Beginners...
Keyword Research | Keyword Research For SEO 2019 | SEO Tutorial For Beginners...Keyword Research | Keyword Research For SEO 2019 | SEO Tutorial For Beginners...
Keyword Research | Keyword Research For SEO 2019 | SEO Tutorial For Beginners...
Simplilearn
 
Clickminded SOP Library
Clickminded SOP LibraryClickminded SOP Library
Clickminded SOP Library
ClickMinded
 

Tendances (20)

Seo
SeoSeo
Seo
 
SEO - Case Study - Digital Marketing
SEO - Case Study - Digital Marketing SEO - Case Study - Digital Marketing
SEO - Case Study - Digital Marketing
 
Social Media Marketing Proposal (1).pdf
Social Media Marketing Proposal (1).pdfSocial Media Marketing Proposal (1).pdf
Social Media Marketing Proposal (1).pdf
 
Google Tag Manager (GTM)
Google Tag Manager (GTM)Google Tag Manager (GTM)
Google Tag Manager (GTM)
 
Quality Content at Scale Through Automated Text Summarization of UGC
Quality Content at Scale Through Automated Text Summarization of UGCQuality Content at Scale Through Automated Text Summarization of UGC
Quality Content at Scale Through Automated Text Summarization of UGC
 
GDO - Google Discover Optimization - (Congreso Web 2019)
GDO - Google Discover Optimization - (Congreso Web 2019)GDO - Google Discover Optimization - (Congreso Web 2019)
GDO - Google Discover Optimization - (Congreso Web 2019)
 
Keyword Research | Keyword Research For SEO 2019 | SEO Tutorial For Beginners...
Keyword Research | Keyword Research For SEO 2019 | SEO Tutorial For Beginners...Keyword Research | Keyword Research For SEO 2019 | SEO Tutorial For Beginners...
Keyword Research | Keyword Research For SEO 2019 | SEO Tutorial For Beginners...
 
Hacking GA4 for SEO - Brighton SEO - Apr 2023
Hacking GA4 for SEO - Brighton SEO - Apr 2023Hacking GA4 for SEO - Brighton SEO - Apr 2023
Hacking GA4 for SEO - Brighton SEO - Apr 2023
 
El SEO en medios: En busca del engranaje perfecto en una redacción
El SEO en medios: En busca del engranaje perfecto en una redacciónEl SEO en medios: En busca del engranaje perfecto en una redacción
El SEO en medios: En busca del engranaje perfecto en una redacción
 
Jen Penaluna: Red Light, Green Light Interviewing Potential Employers | Brigh...
Jen Penaluna: Red Light, Green Light Interviewing Potential Employers | Brigh...Jen Penaluna: Red Light, Green Light Interviewing Potential Employers | Brigh...
Jen Penaluna: Red Light, Green Light Interviewing Potential Employers | Brigh...
 
Google Tag Manager (GTM)
Google Tag Manager (GTM)Google Tag Manager (GTM)
Google Tag Manager (GTM)
 
Google Data Studio NC Tech 4 Good
Google Data Studio NC Tech 4 GoodGoogle Data Studio NC Tech 4 Good
Google Data Studio NC Tech 4 Good
 
SEO desde la línea de comandos
SEO desde la línea de comandosSEO desde la línea de comandos
SEO desde la línea de comandos
 
PubCon, Lazarina Stoy. - Machine Learning in Search: Google's ML APIs vs Open...
PubCon, Lazarina Stoy. - Machine Learning in Search: Google's ML APIs vs Open...PubCon, Lazarina Stoy. - Machine Learning in Search: Google's ML APIs vs Open...
PubCon, Lazarina Stoy. - Machine Learning in Search: Google's ML APIs vs Open...
 
Internship presentation
Internship presentationInternship presentation
Internship presentation
 
How to Optimize Your LinkedIn Presence to Generate New Business
How to Optimize Your LinkedIn Presence to Generate New BusinessHow to Optimize Your LinkedIn Presence to Generate New Business
How to Optimize Your LinkedIn Presence to Generate New Business
 
Clickminded SOP Library
Clickminded SOP LibraryClickminded SOP Library
Clickminded SOP Library
 
Creative seo proposal(1)
Creative seo proposal(1)Creative seo proposal(1)
Creative seo proposal(1)
 
El poder del estilo para impactar tu SEO - César Aparicio, Cráneo Previlegiad...
El poder del estilo para impactar tu SEO - César Aparicio, Cráneo Previlegiad...El poder del estilo para impactar tu SEO - César Aparicio, Cráneo Previlegiad...
El poder del estilo para impactar tu SEO - César Aparicio, Cráneo Previlegiad...
 
BrightonSEO March 2021 | Dan Taylor, Image Entity Tags
BrightonSEO March 2021 | Dan Taylor, Image Entity TagsBrightonSEO March 2021 | Dan Taylor, Image Entity Tags
BrightonSEO March 2021 | Dan Taylor, Image Entity Tags
 

En vedette

The django book - Chap10 : Advanced Models
The django book - Chap10 : Advanced ModelsThe django book - Chap10 : Advanced Models
The django book - Chap10 : Advanced Models
Spin Lai
 
Building Dynamic Websites With Joomla CMS
Building Dynamic Websites With Joomla CMSBuilding Dynamic Websites With Joomla CMS
Building Dynamic Websites With Joomla CMS
Thomas Siegers
 
International marketing (1)
International marketing (1)International marketing (1)
International marketing (1)
Ganpurev Ganbold
 

En vedette (15)

Developing a Solid Content Strategy
Developing a Solid Content StrategyDeveloping a Solid Content Strategy
Developing a Solid Content Strategy
 
EDF2013: Big Data Tutorial: Marko Grobelnik
EDF2013: Big Data Tutorial: Marko GrobelnikEDF2013: Big Data Tutorial: Marko Grobelnik
EDF2013: Big Data Tutorial: Marko Grobelnik
 
Semantic Wiki For The Enterprise
Semantic Wiki For The EnterpriseSemantic Wiki For The Enterprise
Semantic Wiki For The Enterprise
 
Cognos Software Development Kit
Cognos Software Development KitCognos Software Development Kit
Cognos Software Development Kit
 
The django book - Chap10 : Advanced Models
The django book - Chap10 : Advanced ModelsThe django book - Chap10 : Advanced Models
The django book - Chap10 : Advanced Models
 
Building Dynamic Websites With Joomla CMS
Building Dynamic Websites With Joomla CMSBuilding Dynamic Websites With Joomla CMS
Building Dynamic Websites With Joomla CMS
 
Integrating CMS and eCommerce platforms
Integrating CMS and eCommerce platformsIntegrating CMS and eCommerce platforms
Integrating CMS and eCommerce platforms
 
Django rest framework tips and tricks
Django rest framework   tips and tricksDjango rest framework   tips and tricks
Django rest framework tips and tricks
 
IBM Cognos TM1 Version 10.1 Demonstration and Financial Planning Best Practic...
IBM Cognos TM1 Version 10.1 Demonstration and Financial Planning Best Practic...IBM Cognos TM1 Version 10.1 Demonstration and Financial Planning Best Practic...
IBM Cognos TM1 Version 10.1 Demonstration and Financial Planning Best Practic...
 
Marketing Management Notes Unit I
Marketing Management Notes   Unit   IMarketing Management Notes   Unit   I
Marketing Management Notes Unit I
 
What is a Content Management System or CMS
What is a Content Management System or CMSWhat is a Content Management System or CMS
What is a Content Management System or CMS
 
International marketing (1)
International marketing (1)International marketing (1)
International marketing (1)
 
An Overview of Models in Django
An Overview of Models in DjangoAn Overview of Models in Django
An Overview of Models in Django
 
Learn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesLearn 90% of Python in 90 Minutes
Learn 90% of Python in 90 Minutes
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to Python
 

Similaire à Dynamic Models with Django

Customizing the Django Admin
Customizing the Django AdminCustomizing the Django Admin
Customizing the Django Admin
Lincoln Loop
 
Rapid Prototyping with TurboGears2
Rapid Prototyping with TurboGears2Rapid Prototyping with TurboGears2
Rapid Prototyping with TurboGears2
Alessandro Molina
 

Similaire à Dynamic Models with Django (20)

Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
Introduction to django framework
Introduction to django frameworkIntroduction to django framework
Introduction to django framework
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
Graph Gurus 15: Introducing TigerGraph 2.4
Graph Gurus 15: Introducing TigerGraph 2.4 Graph Gurus 15: Introducing TigerGraph 2.4
Graph Gurus 15: Introducing TigerGraph 2.4
 
Droidcon Paris 2015
Droidcon Paris 2015Droidcon Paris 2015
Droidcon Paris 2015
 
Customizing the Django Admin
Customizing the Django AdminCustomizing the Django Admin
Customizing the Django Admin
 
Agile methodologiesvswaterfall
Agile methodologiesvswaterfallAgile methodologiesvswaterfall
Agile methodologiesvswaterfall
 
Drools & jBPM Workshop London 2013
Drools & jBPM Workshop London 2013Drools & jBPM Workshop London 2013
Drools & jBPM Workshop London 2013
 
Web Traffic Time Series Forecasting
Web Traffic  Time Series ForecastingWeb Traffic  Time Series Forecasting
Web Traffic Time Series Forecasting
 
Django interview Questions| Edureka
Django interview  Questions| EdurekaDjango interview  Questions| Edureka
Django interview Questions| Edureka
 
TextEditor - Designing open source apps
TextEditor - Designing open source appsTextEditor - Designing open source apps
TextEditor - Designing open source apps
 
The MEAN stack - SoCalCodeCamp - june 29th 2014
The MEAN stack - SoCalCodeCamp - june 29th 2014The MEAN stack - SoCalCodeCamp - june 29th 2014
The MEAN stack - SoCalCodeCamp - june 29th 2014
 
Rapid Prototyping with TurboGears2
Rapid Prototyping with TurboGears2Rapid Prototyping with TurboGears2
Rapid Prototyping with TurboGears2
 
Bootiful Reactive Testing - Mario Gray
Bootiful Reactive Testing - Mario GrayBootiful Reactive Testing - Mario Gray
Bootiful Reactive Testing - Mario Gray
 
Types of models
Types of modelsTypes of models
Types of models
 
How To Transform the Manual Testing Process to Incorporate Test Automation
How To Transform the Manual Testing Process to Incorporate Test AutomationHow To Transform the Manual Testing Process to Incorporate Test Automation
How To Transform the Manual Testing Process to Incorporate Test Automation
 
Agile - Scrum Presentation
Agile - Scrum PresentationAgile - Scrum Presentation
Agile - Scrum Presentation
 
BDD with SpecFlow and Selenium
BDD with SpecFlow and SeleniumBDD with SpecFlow and Selenium
BDD with SpecFlow and Selenium
 
What are the basic key points to focus on while learning Full-stack web devel...
What are the basic key points to focus on while learning Full-stack web devel...What are the basic key points to focus on while learning Full-stack web devel...
What are the basic key points to focus on while learning Full-stack web devel...
 
Django Workflow and Architecture
Django Workflow and ArchitectureDjango Workflow and Architecture
Django Workflow and Architecture
 

Dernier

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Dernier (20)

[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 

Dynamic Models with Django

  • 1. Dynamic Models in Django Juergen Schackmann j.schackmann@reliatec.de
  • 2. © Juergen Schackmann 2013 2/28 Me ▸ Python & Django since 4 years ▸ reliatec.de since 3 months ▸ Django Web Applications ▸ Focus: EDC systems for clinical studies & Telemonitoring
  • 3. © Juergen Schackmann 2013 3/28 Objective ▸ Why do do we care about Django Dynamic Models? ▸ Why do we have to talk about them? ▸ What should we do about them?
  • 5. © Juergen Schackmann 2013 5/28 Models in a Django project Phase1: Code Development Models and model attributes are defined by implementing those with Python code Phase 2: Deployment Underlying database tables and columns are created by running “syncdb” command Phase 3: Runtime Models / DB Tables are populated with content as part of the user interactions
  • 6. © Juergen Schackmann 2013 6/28 Problem? There is no way to adapt the Django Models at runtime based on user interactions ▸ Django Models are defined and implemented during development phase ▸ Django Models are expected to be static after deployment ▸ Django DB Backends only fully support SQL databases, i.e. a schema is required ▸ DB specific solutions limit adoption rate of any reusable App
  • 7. Use Cases for Dynamic Models
  • 8. © Juergen Schackmann 2013 8/28 Custom Content Types for a CMS* * system: dotCms (Java); source: http://dotcms.com/
  • 9. © Juergen Schackmann 2013 9/28 Customized Products for an Ecommerce Shop* * system: Magento (PHP); source: averybrandandprint.co.uk
  • 10. © Juergen Schackmann 2013 10/28 Clinical Research Forms* * system: OpenClinica (Java); source: openclinica.com
  • 11. © Juergen Schackmann 2013 11/28 Problem? Which Problem? ▸ Models / Content Types are domain or site specific ▸ Neither realistic nor efficient to implement all thinkable content types into a software product ▸ Configuration by subject-matter experts is better, than code customization by developers ▸ Dynamic Models reduce the number of deployment cycles
  • 13. © Juergen Schackmann 2013 13/28 As a User, I ... ▸ want to maintain my dynamic models easily without understanding any Django Model details ▸ want extend existing (static) models without thinking about static and dynamic parts ▸ do not want to think about performance, when creating my custom fields ▸ I want to be able to query/search for certain information seamlessly over static and dynamic models
  • 14. © Juergen Schackmann 2013 14/28 As a developer, I ... ▸ want my dynamic models to be integrated with Django Standard Tools (admin, migrations, reversion) out of the box ▸ want to apply the same API that I use for the static models ▸ do not want to use or be limited to specific databases, but use the standard Django backends ▸ want to have a customizable front-end for my users to manage the dynamic models
  • 15. © Juergen Schackmann 2013 15/28 Evaluation Criteria ▸ Performance ▸ “Querybility” ▸ Django Standard Tools Integration (Admin, Cache, ...) ▸ Supported Backend ▸ Complexity/ Maintainability
  • 16. © Juergen Schackmann 2013 16/28 Entity Attribute Value (EAV) Transform your table columns into table rows Attribute 1 Attribute 2 Attribute n Table Attribute Name Attribute Value Attribute TableTable has1 n
  • 17. © Juergen Schackmann 2013 17/28 EAV Django Apps ▸ bitbucket.org/neithere/eav-django/ ▸ github.com/mvpdev/django-eav
  • 18. © Juergen Schackmann 2013 18/28 Serialized Dictionary Transform your table columns into pickeld or jsoned dictionaries Attribute 1 Attribute 2 Attribute n Table Dictionary String Attributes {“attribute1”:”a”, “attribute2”: 5, “attribute3”:[1,2] }
  • 19. © Juergen Schackmann 2013 19/28 Serialized Dictionary Django Apps Fields ▸ bitbucket.org/schinckel/django-jsonfield/ ▸ github.com/bradjasper/django-jsonfield ▸ github.com/derek-schaefer/django-json-field ▸ github.com/shrubberysoft/django-picklefield App ▸ github.com/dobarkod/django-dynamic-model
  • 20. © Juergen Schackmann 2013 20/28 Runtime Schema Updates Update Django models and database schema at runtime using ▸ syncdb functionality ▸ South functionality ▸ eventually: Andrew Godwin's “Schema Migrations for Django”
  • 21. © Juergen Schackmann 2013 21/28 Runtime Schema Update Django Apps Update Django models and database schema at runtime using ▸ Syncdb ▸ bitbucket.org/mhall119/dynamo/overview ▸ South ▸ github.com/willhardy/dynamic-models ▸ github.com/willhardy/django-dymo ▸ bitbucket.org/schacki/django-dynamo ▸ github.com/charettes/django-mutant ▸ Schema Migrations ▸ github.com/charettes/django-mutant
  • 22. © Juergen Schackmann 2013 22/28 Database specific solutions Hstore ▸ github.com/jordanm/django-hstore ▸ postgresql.org/docs/9.0/static/hstore.html No SQL ▸ github.com/django-nonrel ▸ github.com/pydanny/django-mongonaut
  • 23. © Juergen Schackmann 2013 23/28 Summary EAV Serialization Schema Updates Performance    Querybility    Django Standard Tools  /  Supported Backend    Complexity/ Maintainability   
  • 24. © Juergen Schackmann 2013 24/28 Schema Update most powerful, but ... ▸ Name clashes between developer models and dynamic models (especially with schema migrations) ▸ Multiple Users updating the same model (possibly even conflicting) ▸ Orphan database elements ▸ Dynamic Model loading at startup ▸ How to find/inject dynamic models into views and templates
  • 26. © Juergen Schackmann 2013 26/28 Must have components of a Dynamic Model Application ▸ Meta Model Front End to let users maintain their meta models ▸ Meta Model Representation to store the meta model information ▸ Meta Model Analyzer to detect changes that require some further actions (for schema, admin or model) ▸ Schema Sync Manager to update and sync the database schema ▸ Admin Sync Manager to update and sync the Django admin ▸ Model/Cache Sync Manager to update and sync the Django models and model cache
  • 27. © Juergen Schackmann 2013 27/28 More resources on dynamic models ▸ code.djangoproject.com/wiki/DynamicModels ▸ djangopackages.com/grids/g/forms/ ▸ stackoverflow.com/questions/7933596/django-dynamic-model- fields/7934577
  • 28. Thank you very much! Questions please?