SlideShare une entreprise Scribd logo
1  sur  39
Télécharger pour lire hors ligne
Demystifying Mixins
with Django
@anabalica
Mixins are
a controlled
way of adding
functionality
to classes.
Mixins are not
special language
constructs.
In fact, mixins are
ordinary Python classes.
1 class SomeMixin(object):
2 """My smart mixin"""
3
4 def test_method(self):
5 pass
Why use mixins?
to improve modularity
When to use mixins?
want to reuse a
particular feature in a lot
of different classes
Properties
• single responsibility
• not meant to be extended
• not meant to be instantiated
In Python the concept of
mixins is implemented using
multiple inheritance.
Order matters
1 class Foo(BaseFoo, SomeMixin):
2 pass
base class mixin
1 class Foo(BaseFoo, SomeMixin):
2 pass
1 class Foo(SomeMixin, BaseFoo):
2 pass
1 # some_app/views.py
2 from django.views.generic import TemplateView
3
4
5 class AboutView(TemplateView):
6 template_name = "about.html"
1 # some_app/views.py
2 from django.views.generic import TemplateView
3
4
5 class AboutView(SomeMixin, TemplateView):
6 template_name = "about.html"
My first mixin
1 # some_app/views.py
2
3
4 class LoginRequiredMixin(object):
5
1 # some_app/views.py
2
3
4 class LoginRequiredMixin(object):
5
6 def dispatch(self, request, *args, **kwargs):
7
1 # some_app/views.py
2 from django.core.exceptions import PermissionDenied
3
4
5 class LoginRequiredMixin(object):
6
7 def dispatch(self, request, *args, **kwargs):
8 if not request.user.is_authenticated():
9 raise PermissionDenied
10
1 # some_app/views.py
2 from django.core.exceptions import PermissionDenied
3
4
5 class LoginRequiredMixin(object):
6
7 def dispatch(self, request, *args, **kwargs):
8 if not request.user.is_authenticated():
9 raise PermissionDenied
10
11 return super(LoginRequiredMixin, self).
12 dispatch(request, *args, **kwargs)
13
1 # some_app/views.py
2 from django.views.generic import TemplateView
3
4
5 class AboutView(LoginRequiredMixin, TemplateView):
6 template_name = "about.html"
LoginRequiredMixin TemplateView
AboutView
LoginRequiredMixin DetailView
AboutView
ListView
LoginRequiredListView
AboutView
CreateView
LoginRequiredCreateView
AboutView
DetailView
LoginRequiredDetailView
AboutView
FormView
LoginRequiredFormView
AboutView
MyView
LoginRequiredMyView
AboutView
TemplateView
LoginRequiredTemplateView
AboutView
LoginRequiredMixin TemplateView
AboutView
dispatch()
get_context_data()
get_template_names()
check if user is logged in,
has permission
add new data to
the context
add more flexibility to
the template names
1 # some_app/views.py
2 from django.views.generic import TemplateView
3
4
5 class AboutView(TemplateView):
6 template_name = "about.html"
dispatch()
get_context_data()
get_template_names()
check if user is logged in,
has permission
add new data to
the context
add more flexibility to
the template names
docs.djangoproject.com/en/1.8/ref/
class-based-views/base/
docs.djangoproject.com/en/1.8/ref/
class-based-views/base/
docs.djangoproject.com/en/1.8/topics/
class-based-views/mixins/
docs.djangoproject.com/en/1.8/topics/
class-based-views/mixins/
ccbv.co.uk/
django-braces
Access
Mixins
Form
Mixins
Other
Mixins
With great
power comes great
responsibility
Recap
• single responsibility
• plug-in functionality
• isn’t creating a subtyping
relation
Go back to your views
and start writing mixins
to clean up the code.

Contenu connexe

Tendances

37 Java Interview Questions
37 Java Interview Questions37 Java Interview Questions
37 Java Interview QuestionsArc & Codementor
 
Chapter 05 polymorphism extra
Chapter 05 polymorphism extraChapter 05 polymorphism extra
Chapter 05 polymorphism extraNurhanna Aziz
 
Class notes(week 9) on multithreading
Class notes(week 9) on multithreadingClass notes(week 9) on multithreading
Class notes(week 9) on multithreadingKuntal Bhowmick
 
Ppt on this and super keyword
Ppt on this and super keywordPpt on this and super keyword
Ppt on this and super keywordtanu_jaswal
 
Interview Questions and Answers for Java
Interview Questions and Answers for JavaInterview Questions and Answers for Java
Interview Questions and Answers for JavaGaruda Trainings
 
Most Asked Java Interview Question and Answer
Most Asked Java Interview Question and AnswerMost Asked Java Interview Question and Answer
Most Asked Java Interview Question and AnswerTOPS Technologies
 
encapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloadingencapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloadingShivam Singhal
 
Java interview questions 2
Java interview questions 2Java interview questions 2
Java interview questions 2Sherihan Anver
 

Tendances (10)

37 Java Interview Questions
37 Java Interview Questions37 Java Interview Questions
37 Java Interview Questions
 
Chapter 05 polymorphism extra
Chapter 05 polymorphism extraChapter 05 polymorphism extra
Chapter 05 polymorphism extra
 
L5
L5L5
L5
 
Class notes(week 9) on multithreading
Class notes(week 9) on multithreadingClass notes(week 9) on multithreading
Class notes(week 9) on multithreading
 
Ppt on this and super keyword
Ppt on this and super keywordPpt on this and super keyword
Ppt on this and super keyword
 
Java interface
Java interfaceJava interface
Java interface
 
Interview Questions and Answers for Java
Interview Questions and Answers for JavaInterview Questions and Answers for Java
Interview Questions and Answers for Java
 
Most Asked Java Interview Question and Answer
Most Asked Java Interview Question and AnswerMost Asked Java Interview Question and Answer
Most Asked Java Interview Question and Answer
 
encapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloadingencapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloading
 
Java interview questions 2
Java interview questions 2Java interview questions 2
Java interview questions 2
 

En vedette

[Djangocon2015][Lightning talk] Systers
[Djangocon2015][Lightning talk] Systers[Djangocon2015][Lightning talk] Systers
[Djangocon2015][Lightning talk] SystersAna Balica
 
Quantum visionsystem
Quantum visionsystemQuantum visionsystem
Quantum visionsystemJames Santos
 
Debugging with pdb in Python
Debugging with pdb in PythonDebugging with pdb in Python
Debugging with pdb in PythonAna Balica
 
DJUGL 2015 Signals and AppConfig
DJUGL 2015 Signals and AppConfigDJUGL 2015 Signals and AppConfig
DJUGL 2015 Signals and AppConfigAna Balica
 
[EuroPython2015] Demystifying Mixins with Django
[EuroPython2015] Demystifying Mixins with Django[EuroPython2015] Demystifying Mixins with Django
[EuroPython2015] Demystifying Mixins with DjangoAna Balica
 
How to write a good commit message
How to write a good commit messageHow to write a good commit message
How to write a good commit messageAna Balica
 

En vedette (10)

[Djangocon2015][Lightning talk] Systers
[Djangocon2015][Lightning talk] Systers[Djangocon2015][Lightning talk] Systers
[Djangocon2015][Lightning talk] Systers
 
2015
20152015
2015
 
Quantum visionsystem
Quantum visionsystemQuantum visionsystem
Quantum visionsystem
 
Livestream aaf-may2015
Livestream aaf-may2015Livestream aaf-may2015
Livestream aaf-may2015
 
Debugging with pdb in Python
Debugging with pdb in PythonDebugging with pdb in Python
Debugging with pdb in Python
 
Darbas su tėvais
Darbas su tėvaisDarbas su tėvais
Darbas su tėvais
 
Regėjimo sutrikimai
Regėjimo sutrikimaiRegėjimo sutrikimai
Regėjimo sutrikimai
 
DJUGL 2015 Signals and AppConfig
DJUGL 2015 Signals and AppConfigDJUGL 2015 Signals and AppConfig
DJUGL 2015 Signals and AppConfig
 
[EuroPython2015] Demystifying Mixins with Django
[EuroPython2015] Demystifying Mixins with Django[EuroPython2015] Demystifying Mixins with Django
[EuroPython2015] Demystifying Mixins with Django
 
How to write a good commit message
How to write a good commit messageHow to write a good commit message
How to write a good commit message
 

Similaire à [Djangocon2015] Demystifying mixins with Django

full defination of final opp.pptx
full defination of final opp.pptxfull defination of final opp.pptx
full defination of final opp.pptxrayanbabur
 
Java questions for interview
Java questions for interviewJava questions for interview
Java questions for interviewKuntal Bhowmick
 
1669617800196.pdf
1669617800196.pdf1669617800196.pdf
1669617800196.pdfvenud11
 
Control structures functions and modules in python programming
Control structures functions and modules in python programmingControl structures functions and modules in python programming
Control structures functions and modules in python programmingSrinivas Narasegouda
 
Synapseindia reviews.odp.
Synapseindia reviews.odp.Synapseindia reviews.odp.
Synapseindia reviews.odp.Tarunsingh198
 
520_DevOps Engineer Master Program Curriculum.pdf
520_DevOps Engineer Master Program Curriculum.pdf520_DevOps Engineer Master Program Curriculum.pdf
520_DevOps Engineer Master Program Curriculum.pdfAniruddhNain1
 
Android App Architecture with modern libs in practice. Our way in R.I.D., Ser...
Android App Architecture with modern libs in practice. Our way in R.I.D., Ser...Android App Architecture with modern libs in practice. Our way in R.I.D., Ser...
Android App Architecture with modern libs in practice. Our way in R.I.D., Ser...Sigma Software
 
Java Core Parctical
Java Core ParcticalJava Core Parctical
Java Core ParcticalGaurav Mehta
 
Java tutorials
Java tutorialsJava tutorials
Java tutorialssaryu2011
 
Pragmatic plone projects
Pragmatic plone projectsPragmatic plone projects
Pragmatic plone projectsAndreas Jung
 
Object oriented basics
Object oriented basicsObject oriented basics
Object oriented basicsvamshimahi
 
OOP Lecture 5-Inheritance,Dialogboxes,Parsing.pptx
OOP Lecture 5-Inheritance,Dialogboxes,Parsing.pptxOOP Lecture 5-Inheritance,Dialogboxes,Parsing.pptx
OOP Lecture 5-Inheritance,Dialogboxes,Parsing.pptxTanzila Kehkashan
 
Pragmatische Plone Projekte
Pragmatische Plone ProjektePragmatische Plone Projekte
Pragmatische Plone ProjekteAndreas Jung
 
Greach 2014 - Metaprogramming with groovy
Greach 2014 - Metaprogramming with groovyGreach 2014 - Metaprogramming with groovy
Greach 2014 - Metaprogramming with groovyIván López Martín
 
Learn Polymorphism in Python with Examples.pdf
Learn Polymorphism in Python with Examples.pdfLearn Polymorphism in Python with Examples.pdf
Learn Polymorphism in Python with Examples.pdfDatacademy.ai
 

Similaire à [Djangocon2015] Demystifying mixins with Django (20)

full defination of final opp.pptx
full defination of final opp.pptxfull defination of final opp.pptx
full defination of final opp.pptx
 
JavaHTP6e_10.ppt
JavaHTP6e_10.pptJavaHTP6e_10.ppt
JavaHTP6e_10.ppt
 
Java questions for interview
Java questions for interviewJava questions for interview
Java questions for interview
 
1669617800196.pdf
1669617800196.pdf1669617800196.pdf
1669617800196.pdf
 
Control structures functions and modules in python programming
Control structures functions and modules in python programmingControl structures functions and modules in python programming
Control structures functions and modules in python programming
 
Unit-V.pptx
Unit-V.pptxUnit-V.pptx
Unit-V.pptx
 
Synapseindia reviews.odp.
Synapseindia reviews.odp.Synapseindia reviews.odp.
Synapseindia reviews.odp.
 
520_DevOps Engineer Master Program Curriculum.pdf
520_DevOps Engineer Master Program Curriculum.pdf520_DevOps Engineer Master Program Curriculum.pdf
520_DevOps Engineer Master Program Curriculum.pdf
 
Android App Architecture with modern libs in practice. Our way in R.I.D., Ser...
Android App Architecture with modern libs in practice. Our way in R.I.D., Ser...Android App Architecture with modern libs in practice. Our way in R.I.D., Ser...
Android App Architecture with modern libs in practice. Our way in R.I.D., Ser...
 
Inheritance
InheritanceInheritance
Inheritance
 
Java Core Parctical
Java Core ParcticalJava Core Parctical
Java Core Parctical
 
Php oop (1)
Php oop (1)Php oop (1)
Php oop (1)
 
Java tutorials
Java tutorialsJava tutorials
Java tutorials
 
Pragmatic plone projects
Pragmatic plone projectsPragmatic plone projects
Pragmatic plone projects
 
Object oriented basics
Object oriented basicsObject oriented basics
Object oriented basics
 
OOP Lecture 5-Inheritance,Dialogboxes,Parsing.pptx
OOP Lecture 5-Inheritance,Dialogboxes,Parsing.pptxOOP Lecture 5-Inheritance,Dialogboxes,Parsing.pptx
OOP Lecture 5-Inheritance,Dialogboxes,Parsing.pptx
 
Pragmatische Plone Projekte
Pragmatische Plone ProjektePragmatische Plone Projekte
Pragmatische Plone Projekte
 
Modules in Python
Modules in PythonModules in Python
Modules in Python
 
Greach 2014 - Metaprogramming with groovy
Greach 2014 - Metaprogramming with groovyGreach 2014 - Metaprogramming with groovy
Greach 2014 - Metaprogramming with groovy
 
Learn Polymorphism in Python with Examples.pdf
Learn Polymorphism in Python with Examples.pdfLearn Polymorphism in Python with Examples.pdf
Learn Polymorphism in Python with Examples.pdf
 

Dernier

Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
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...Martijn de Jong
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 

Dernier (20)

Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
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...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 

[Djangocon2015] Demystifying mixins with Django