SlideShare a Scribd company logo
1 of 37
What’s new in Django 1.2?



Jacob Kaplan-Moss
Databases/Models
GSo
                                 C



Multiple databases
     http://bit.ly/multi-db
# settings.py

DATABASES = {
  'default': {
     'ENGINE': 'django.db.backends.mysql',
     'NAME': 'mydb',
  },
  'other': {
     'ENGINE': 'django.db.backends.sqlite3'
     'NAME': '/path/to/db'
  }
}
>>> MyModel.objects.all()
[...]

>>> MyModel.objects.using('other').all()
[...]

>>> instance = MyModel(...)
>>> instance.save(using='default')
C
                                                    om
                                                     in
# yourapp/routers.py




                                                        g
                                                         so
class MasterSlaveRouter(object):




                                                            on
   def db_for_read(model, instance=None):




                                                              !
     return random.choice(['slave1', 'slave2'])

  def db_for_write(model, instance=None):
    return 'master'




# settings.py

DATABASE_ROUTERS = ['path.to.MasterSlaveRouter']
Raw queries
  http://bit.ly/raw-sql
>>> Person.objects.raw('SELECT * FROM authors')
[<Person: Phillip Roth>, <Person: Robert A. Wilson>, ...]

>>> Person.objects.raw('SELECT id, first_name, "Joe" AS last_name FROM authors')
[<Person: Joe Roth>, <Person: Joe A. Wilson>, ...]

>>> people = Person.objects.raw('SELECT *, age(birth_date) AS age FROM authors')
>>> for p in people:
... print "%s is %s." % (p.first_name, p.age)
Phillip is 78.
Robert is 102.
...
GSo
                              C



Validators
http://bit.ly/validators
from django.core.exceptions import ValidationError

def is_even(value):
  if value % 2 != 0:
      raise ValidationError("%s is not an even number." % value)

...

class MyModel(models.Model):
   even = models.IntegerField(validators=[is_even])

...

class MyForm(forms.Form):
   even = forms.IntegerField(validators=[is_even])
Template
improvements
Improved CSRF protection
       http://bit.ly/django-csrf
{% if x > y %}


{% if x|lower = 'q' %}


{% if x.y.z in list %}
Cached template loading
     http://bit.ly/template-loaders
New in django.contrib
User messaging
 http://bit.ly/django-messages
from django.contrib import messages

def my_view(request):
  messages.success(request, "It worked!")
  messages.error(request, "FAIL")
  # Also debug, info, and wanrning

...

{% if messages %}
 <ul class="messages">
   {% for message in messages %}
     <li class="{{ message.tags }}">{{ message }}</li>
   {% endfor %}
 </ul>
{% endif %}
Testing improvements
~40% faster
Natural keys in fixtures
      http://bit.ly/natural-keys
./manage.py test --failfast
Et cetera
http://bit.ly/django-12
Et cetera
http://bit.ly/django-12

 • Python 2.4+
Et cetera
http://bit.ly/django-12

 • Python 2.4+
 • Email backends
Et cetera
http://bit.ly/django-12

 • Python 2.4+
 • Email backends
 • QuerySet.exists()
Et cetera
http://bit.ly/django-12

 • Python 2.4+
 • Email backends
 • QuerySet.exists()
 • Class-based test runners
Et cetera
http://bit.ly/django-12

 • Python 2.4+
 • Email backends
 • QuerySet.exists()
 • Class-based test runners
 • Improvements to GeoDjango’s inspectdb
Et cetera
http://bit.ly/django-12

 • Python 2.4+
 • Email backends
 • QuerySet.exists()
 • Class-based test runners
 • Improvements to GeoDjango’s inspectdb
 • Read-only fields in the admin
Et cetera
http://bit.ly/django-12

 • Python 2.4+
 • Email backends
 • QuerySet.exists()
 • Class-based test runners
 • Improvements to GeoDjango’s inspectdb
 • Read-only fields in the admin
 • BigIntegerField
Et cetera
http://bit.ly/django-12

 • Python 2.4+
 • Email backends
 • QuerySet.exists()
 • Class-based test runners
 • Improvements to GeoDjango’s inspectdb
 • Read-only fields in the admin
 • BigIntegerField
 • Localization improvements
Et cetera
http://bit.ly/django-12

 • Python 2.4+
 • Email backends
 • QuerySet.exists()
 • Class-based test runners
 • Improvements to GeoDjango’s inspectdb
 • Read-only fields in the admin
 • BigIntegerField
 • Localization improvements
 • Hooks for row-level permissions
Et cetera
http://bit.ly/django-12

 • Python 2.4+
 • Email backends
 • QuerySet.exists()
 • Class-based test runners
 • Improvements to GeoDjango’s inspectdb
 • Read-only fields in the admin
 • BigIntegerField
 • Localization improvements
 • Hooks for row-level permissions
 • Real models for automatic many-to-many tables
When?
When?


• January 26: Django 1.2 beta.
When?


• January 26: Django 1.2 beta.
• March 2: Django 1.2 release candidate.
When?


• January 26: Django 1.2 beta.
• March 2: Django 1.2 release candidate.
• March 9: Django 1.2 final.
Questions?


   Me: Jacob Kaplan-Moss
 Email: jacob@jacobian.org
Twitter: @jacobian

More Related Content

What's hot

Building Better Applications with Data::Manager
Building Better Applications with Data::ManagerBuilding Better Applications with Data::Manager
Building Better Applications with Data::Manager
Jay Shirley
 
Metaprogramovanie #1
Metaprogramovanie #1Metaprogramovanie #1
Metaprogramovanie #1
Jano Suchal
 
Database API, your new friend
Database API, your new friendDatabase API, your new friend
Database API, your new friend
kikoalonsob
 
20 modules i haven't yet talked about
20 modules i haven't yet talked about20 modules i haven't yet talked about
20 modules i haven't yet talked about
Tatsuhiko Miyagawa
 
international PHP2011_Bastian Feder_jQuery's Secrets
international PHP2011_Bastian Feder_jQuery's Secretsinternational PHP2011_Bastian Feder_jQuery's Secrets
international PHP2011_Bastian Feder_jQuery's Secrets
smueller_sandsmedia
 
Twib in Yokoahma.pm 2010/3/5
Twib in Yokoahma.pm 2010/3/5Twib in Yokoahma.pm 2010/3/5
Twib in Yokoahma.pm 2010/3/5
Yusuke Wada
 

What's hot (20)

Building Better Applications with Data::Manager
Building Better Applications with Data::ManagerBuilding Better Applications with Data::Manager
Building Better Applications with Data::Manager
 
jrubykaigi2010-lt-rubeus
jrubykaigi2010-lt-rubeusjrubykaigi2010-lt-rubeus
jrubykaigi2010-lt-rubeus
 
Python magicmethods
Python magicmethodsPython magicmethods
Python magicmethods
 
Doctrine MongoDB ODM (PDXPHP)
Doctrine MongoDB ODM (PDXPHP)Doctrine MongoDB ODM (PDXPHP)
Doctrine MongoDB ODM (PDXPHP)
 
Metaprogramovanie #1
Metaprogramovanie #1Metaprogramovanie #1
Metaprogramovanie #1
 
Lithium: The Framework for People Who Hate Frameworks
Lithium: The Framework for People Who Hate FrameworksLithium: The Framework for People Who Hate Frameworks
Lithium: The Framework for People Who Hate Frameworks
 
Python Magic Methods: a practical example
Python Magic Methods: a practical examplePython Magic Methods: a practical example
Python Magic Methods: a practical example
 
Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition
Lithium: The Framework for People Who Hate Frameworks, Tokyo EditionLithium: The Framework for People Who Hate Frameworks, Tokyo Edition
Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition
 
The Zen of Lithium
The Zen of LithiumThe Zen of Lithium
The Zen of Lithium
 
Lithium Best
Lithium Best Lithium Best
Lithium Best
 
Blog Hacks 2011
Blog Hacks 2011Blog Hacks 2011
Blog Hacks 2011
 
Database API, your new friend
Database API, your new friendDatabase API, your new friend
Database API, your new friend
 
“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHPKonf
“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHPKonf“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHPKonf
“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHPKonf
 
20 modules i haven't yet talked about
20 modules i haven't yet talked about20 modules i haven't yet talked about
20 modules i haven't yet talked about
 
international PHP2011_Bastian Feder_jQuery's Secrets
international PHP2011_Bastian Feder_jQuery's Secretsinternational PHP2011_Bastian Feder_jQuery's Secrets
international PHP2011_Bastian Feder_jQuery's Secrets
 
エロサイト管理者の憂鬱3 - Hokkaiodo.pm#4 -
エロサイト管理者の憂鬱3 - Hokkaiodo.pm#4 -エロサイト管理者の憂鬱3 - Hokkaiodo.pm#4 -
エロサイト管理者の憂鬱3 - Hokkaiodo.pm#4 -
 
Twib in Yokoahma.pm 2010/3/5
Twib in Yokoahma.pm 2010/3/5Twib in Yokoahma.pm 2010/3/5
Twib in Yokoahma.pm 2010/3/5
 
Php unit the-mostunknownparts
Php unit the-mostunknownpartsPhp unit the-mostunknownparts
Php unit the-mostunknownparts
 
Symfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technologySymfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technology
 
Testing your data mart - how to start | DOAG 2021
Testing your data mart - how to start | DOAG 2021Testing your data mart - how to start | DOAG 2021
Testing your data mart - how to start | DOAG 2021
 

Similar to What's new in Django 1.2?

High Performance Django
High Performance DjangoHigh Performance Django
High Performance Django
DjangoCon2008
 
High Performance Django 1
High Performance Django 1High Performance Django 1
High Performance Django 1
DjangoCon2008
 
The Best (and Worst) of Django
The Best (and Worst) of DjangoThe Best (and Worst) of Django
The Best (and Worst) of Django
Jacob Kaplan-Moss
 
Introduction To Django (Strange Loop 2011)
Introduction To Django (Strange Loop 2011)Introduction To Django (Strange Loop 2011)
Introduction To Django (Strange Loop 2011)
Jacob Kaplan-Moss
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overview
Yehuda Katz
 

Similar to What's new in Django 1.2? (20)

Django Vs Rails
Django Vs RailsDjango Vs Rails
Django Vs Rails
 
Django Good Practices
Django Good PracticesDjango Good Practices
Django Good Practices
 
Django tricks (2)
Django tricks (2)Django tricks (2)
Django tricks (2)
 
Тестирование и Django
Тестирование и DjangoТестирование и Django
Тестирование и Django
 
Django
DjangoDjango
Django
 
High Performance Django
High Performance DjangoHigh Performance Django
High Performance Django
 
High Performance Django 1
High Performance Django 1High Performance Django 1
High Performance Django 1
 
The Best (and Worst) of Django
The Best (and Worst) of DjangoThe Best (and Worst) of Django
The Best (and Worst) of Django
 
Django Heresies
Django HeresiesDjango Heresies
Django Heresies
 
Refactor Dance - Puppet Labs 'Best Practices'
Refactor Dance - Puppet Labs 'Best Practices'Refactor Dance - Puppet Labs 'Best Practices'
Refactor Dance - Puppet Labs 'Best Practices'
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
Introduction To Django (Strange Loop 2011)
Introduction To Django (Strange Loop 2011)Introduction To Django (Strange Loop 2011)
Introduction To Django (Strange Loop 2011)
 
Python RESTful webservices with Python: Flask and Django solutions
Python RESTful webservices with Python: Flask and Django solutionsPython RESTful webservices with Python: Flask and Django solutions
Python RESTful webservices with Python: Flask and Django solutions
 
Doing the Refactor Dance - Making Your Puppet Modules More Modular - PuppetCo...
Doing the Refactor Dance - Making Your Puppet Modules More Modular - PuppetCo...Doing the Refactor Dance - Making Your Puppet Modules More Modular - PuppetCo...
Doing the Refactor Dance - Making Your Puppet Modules More Modular - PuppetCo...
 
Symfony2 from the Trenches
Symfony2 from the TrenchesSymfony2 from the Trenches
Symfony2 from the Trenches
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overview
 
Inside PyMongo - MongoNYC
Inside PyMongo - MongoNYCInside PyMongo - MongoNYC
Inside PyMongo - MongoNYC
 
Python Development (MongoSF)
Python Development (MongoSF)Python Development (MongoSF)
Python Development (MongoSF)
 
Using Task Queues and D3.js to build an analytics product on App Engine
Using Task Queues and D3.js to build an analytics product on App EngineUsing Task Queues and D3.js to build an analytics product on App Engine
Using Task Queues and D3.js to build an analytics product on App Engine
 
Django Pro ORM
Django Pro ORMDjango Pro ORM
Django Pro ORM
 

More from Jacob Kaplan-Moss

Writing great documentation - CodeConf 2011
Writing great documentation - CodeConf 2011Writing great documentation - CodeConf 2011
Writing great documentation - CodeConf 2011
Jacob Kaplan-Moss
 
Django Introduction, Dev in Rio 2009
Django Introduction, Dev in Rio 2009Django Introduction, Dev in Rio 2009
Django Introduction, Dev in Rio 2009
Jacob Kaplan-Moss
 
Django - the first five years
Django - the first five yearsDjango - the first five years
Django - the first five years
Jacob Kaplan-Moss
 
A brief history of Django model syntax
A brief history of Django model syntaxA brief history of Django model syntax
A brief history of Django model syntax
Jacob Kaplan-Moss
 

More from Jacob Kaplan-Moss (10)

Writing great documentation - CodeConf 2011
Writing great documentation - CodeConf 2011Writing great documentation - CodeConf 2011
Writing great documentation - CodeConf 2011
 
Django Introduction, Dev in Rio 2009
Django Introduction, Dev in Rio 2009Django Introduction, Dev in Rio 2009
Django Introduction, Dev in Rio 2009
 
Snakes on the Web
Snakes on the WebSnakes on the Web
Snakes on the Web
 
Django In The Real World
Django In The Real WorldDjango In The Real World
Django In The Real World
 
Building a web framework: Django's design decisions
Building a web framework: Django's design decisionsBuilding a web framework: Django's design decisions
Building a web framework: Django's design decisions
 
Django in the Real World
Django in the Real WorldDjango in the Real World
Django in the Real World
 
State Of Django
State Of DjangoState Of Django
State Of Django
 
Django - the first five years
Django - the first five yearsDjango - the first five years
Django - the first five years
 
A brief history of Django model syntax
A brief history of Django model syntaxA brief history of Django model syntax
A brief history of Django model syntax
 
Django Update (OSCON 2007)
Django Update (OSCON 2007)Django Update (OSCON 2007)
Django Update (OSCON 2007)
 

Recently uploaded

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Recently uploaded (20)

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
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
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...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony 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
 
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
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
[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
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
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...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
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
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
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...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 

What's new in Django 1.2?

Editor's Notes

  1. Thank you.