SlideShare a Scribd company logo
1 of 17
Download to read offline
Concepts in Django
Douwe van der Meij
Goldmund, Wyldebeast & Wunderliebe
vandermeij@gw20e.com
github.com/douwevandermeij
Project
INSTALLED_APPS = (
...
'crm',
'webshop',
...
)
Dependencies
● Inter-app foreign
key constraint

crm

Customer

Project

account_nr

● How to reuse
webshop without
crm?

Order
order_nr

webshop

OrderLine
Concepts
Define:
● Producers
○ Contain data

Producer

● Consumers
○ Don’t contain data
○ Need a producer

Consumer
Customer concept
The concept we’re talking about:
● A customer
○ Has a number
Applications with concepts
crm
Producer

Customer

Project

account_nr

webshop
Consumer

Customer
number

Order

OrderLine
Define Producers
Conceptname

CONCEPTS = {
Producer model
'CustomerConcept': {
'crm.models.Customer': {
'number': 'account_nr',
Field mapping
},
},
}

● Map to existing models
Consume
class Order(models.Model):
customer = models.ForeignKey(CustomerConcept)
order_nr = models.IntegerField()
Dependencies
crm

● ORM level
Customer

Customer
CustomerConcept
concepts
Order
webshop

Project
Dependencies

crm

Customer

Order
webshop

Project

● Database level
The magic (1/4)
from django.conf import settings

for concept_name, mapping in settings.CONCEPTS.items():
for klass, fields in mapping.items():
...

● The concepts app
○ Loops over settings.CONCEPTS
The magic (2/4)
from concepts.util import load_class

● Create a dynamic class
● With
in

...
concept = type(
proxy = True
Meta
concept_name,
(load_class(klass),),
{
'__module__': __name__,
'Meta': type('Meta', (), {'proxy': True}),
},
)
...
The magic (3/4)
...
for _property, _field in fields.items():
if not hasattr(concept, _property):
setattr(
concept,
_property,
property(
lambda self: getattr(self, _field),
lambda self, value:
setattr(self, _field, value),
),
)
...

● Create properties for
all fields
The magic (4/4)
import concepts

● Bind the concept to
the concepts module

...
setattr(concepts, concept_name, concept)
Conclusion
● Concepts make apps reusable
○ Without dependencies

● The only dependency
○ Is a concept

● The concept producer
○ You may choose yourself
○ On existing apps
Try it yourself
● github.com /
douwevandermeij /
concepts_example
● Related work
○ Django Swappable Models
■ Like swapping auth.User model in 1.5+
○ Zope Component Architecture
■ Interfaces: implement/adapt
Thank you!
Douwe van der Meij
Goldmund, Wyldebeast & Wunderliebe
vandermeij@gw20e.com
github.com/douwevandermeij

More Related Content

Similar to Concepts in Django

Virtual Sample Software Explained
Virtual Sample Software ExplainedVirtual Sample Software Explained
Virtual Sample Software Explained
Gateway 3D Ltd
 
Quill slides-www2013
Quill slides-www2013Quill slides-www2013
Quill slides-www2013
Vivian Motti
 
Developing enterprise ecommerce solutions using hybris by Drazen Nikolic - Be...
Developing enterprise ecommerce solutions using hybris by Drazen Nikolic - Be...Developing enterprise ecommerce solutions using hybris by Drazen Nikolic - Be...
Developing enterprise ecommerce solutions using hybris by Drazen Nikolic - Be...
youngculture
 
Harnessing 3D for eCommerce
Harnessing 3D for eCommerceHarnessing 3D for eCommerce
Harnessing 3D for eCommerce
Gateway 3D Ltd
 

Similar to Concepts in Django (20)

How to Build a ML Platform Efficiently Using Open-Source
How to Build a ML Platform Efficiently Using Open-SourceHow to Build a ML Platform Efficiently Using Open-Source
How to Build a ML Platform Efficiently Using Open-Source
 
GraphTour - The Workshop - Device Tracking in Practice: From Idea to Production
GraphTour - The Workshop - Device Tracking in Practice: From Idea to ProductionGraphTour - The Workshop - Device Tracking in Practice: From Idea to Production
GraphTour - The Workshop - Device Tracking in Practice: From Idea to Production
 
Indore MuleSoft Meetup #5 April 2022 MDynamics 65.pptx
Indore MuleSoft Meetup #5 April 2022 MDynamics 65.pptxIndore MuleSoft Meetup #5 April 2022 MDynamics 65.pptx
Indore MuleSoft Meetup #5 April 2022 MDynamics 65.pptx
 
Virtual Sample Software Explained
Virtual Sample Software ExplainedVirtual Sample Software Explained
Virtual Sample Software Explained
 
Vehicle Insurance Purchasing System
Vehicle Insurance Purchasing SystemVehicle Insurance Purchasing System
Vehicle Insurance Purchasing System
 
3 d printing business ideas
3 d printing business ideas3 d printing business ideas
3 d printing business ideas
 
Go headless with shopify using vsf next by Viral Rana
Go headless with shopify using vsf next   by Viral RanaGo headless with shopify using vsf next   by Viral Rana
Go headless with shopify using vsf next by Viral Rana
 
Curso 20485 Advanced Windows Store App Development using C# - NEW HORIZONS MA...
Curso 20485 Advanced Windows Store App Development using C# - NEW HORIZONS MA...Curso 20485 Advanced Windows Store App Development using C# - NEW HORIZONS MA...
Curso 20485 Advanced Windows Store App Development using C# - NEW HORIZONS MA...
 
Quill slides-www2013
Quill slides-www2013Quill slides-www2013
Quill slides-www2013
 
Quill slides-www2013
Quill slides-www2013Quill slides-www2013
Quill slides-www2013
 
FrontEnd.pdf
FrontEnd.pdfFrontEnd.pdf
FrontEnd.pdf
 
Online Shopping Platform Design Proposal PowerPoint Presentation Slides
Online Shopping Platform Design Proposal PowerPoint Presentation SlidesOnline Shopping Platform Design Proposal PowerPoint Presentation Slides
Online Shopping Platform Design Proposal PowerPoint Presentation Slides
 
Recurring Revenue: Custom pricing models against standardized billing tools, ...
Recurring Revenue: Custom pricing models against standardized billing tools, ...Recurring Revenue: Custom pricing models against standardized billing tools, ...
Recurring Revenue: Custom pricing models against standardized billing tools, ...
 
Final Year Project.pptx
Final Year Project.pptxFinal Year Project.pptx
Final Year Project.pptx
 
Ecommerce Website Design Proposal PowerPoint Presentation Slides
Ecommerce Website Design Proposal PowerPoint Presentation SlidesEcommerce Website Design Proposal PowerPoint Presentation Slides
Ecommerce Website Design Proposal PowerPoint Presentation Slides
 
Introduction of CRM in Odoo.pdf
Introduction of CRM in Odoo.pdfIntroduction of CRM in Odoo.pdf
Introduction of CRM in Odoo.pdf
 
Lead AI incubations as a Product manager
Lead AI incubations as a Product manager Lead AI incubations as a Product manager
Lead AI incubations as a Product manager
 
Developing enterprise ecommerce solutions using hybris by Drazen Nikolic - Be...
Developing enterprise ecommerce solutions using hybris by Drazen Nikolic - Be...Developing enterprise ecommerce solutions using hybris by Drazen Nikolic - Be...
Developing enterprise ecommerce solutions using hybris by Drazen Nikolic - Be...
 
Introduction of CMS Technology to the People of Tanay, Rizal Philippines
Introduction of CMS Technology to the People of Tanay, Rizal PhilippinesIntroduction of CMS Technology to the People of Tanay, Rizal Philippines
Introduction of CMS Technology to the People of Tanay, Rizal Philippines
 
Harnessing 3D for eCommerce
Harnessing 3D for eCommerceHarnessing 3D for eCommerce
Harnessing 3D for eCommerce
 

Recently uploaded

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
 
+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@
 

Recently uploaded (20)

Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
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
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
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
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
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
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
+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...
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
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
 

Concepts in Django