Date post: | 27-Jan-2015 |
Category: |
Technology |
Upload: | sivasubramaniam-arunachalam |
View: | 108 times |
Download: | 2 times |
What’s New in Django 1.6
Sivasubramaniam Arunachalam
Nov 14, 2013
@sivaa_in
http://www.meetup.com/Bangalore-Django-User-Group/events/149839872/
Malcolm
Tredinnick
(We miss you)
Version Released Date Released After
0.9 Nov 16, 2005
0.91 Jan 11, 2006 2 Months
0.95 Jul 29, 2006 6 Months
0.96 Mar 23, 2007 8 Months
1.0 Sep 03, 2008 17 Months
1.1 Jul 29, 2009 11 Months
1.2 May 17, 2010 9 Months
1.3 Mar 23, 2011 10 Months
1.4 Mar 23, 2012 12 Months
1.5 Feb 26, 2013 11 Months
1.6 Nov 06, 2013 8 Months
Django Version Supported Python
Version (2.x) Supported Python
Version (3.x)
1.0 2.3+
1.1 2.3+
1.2 2.4+
1.3 2.4+
1.4 2.5+
1.5 2.6+ 3.2+*
1.6 2.6+ 3.2+
1.7 2.7+ 3.2+
* Experimental
Python 3 Officially Supported
(Enjoy it in Production)
LTS Releases
https://docs.djangoproject.com/en/dev/internals/release-process/#long-term-support-lts-releases
Django 1.4 till March 2015
New Features
• Simple Layout
• Improved Transactions
• Persistent DB Connections
• Others
New Features
• Simple Layout
• Improved Transactions
• Persistent DB Connections
• Others
Much Simpler (Project & App Layouts)
Application - added admin
- removed sites
Middleware - added clickjacking prevention
Database - SQLite3
New Defaults
Custom Templates (For Projects & Applications)
https://docs.djangoproject.com/en/1.6/ref/django-admin/#custom-app-and-project-templates
startproject
• manage.py
• settings.py
• wsgi.py
• urls.py
startproject
• manage.py
• settings.py
• wsgi.py
• urls.py
Removed Settings
• ADMINS
• MANAGERS
startproject - settings.py
• STATIC_ROOT
• STATICFILES_DIRS
• STATICFILES_FINDERS
• TEMPLATE_DIRS
• TEMPLATE_LOADERS
• MEDIA_ROOT
• MEDIA_URL
• SITE_ID
• LOGGING
Modified Settings
startproject - settings.py
DATABASES (default to SQLite3)
startproject - settings.py - Modified
TIME_ZONE (default to UTC)
startproject - settings.py - Modified
INSTALLED_APPS (admin enabled & sites removed by default)
startproject - settings.py - Modified
MIDDLEWARE_CLASSES (clickjacking protection is enabled by default)
startproject - settings.py - Modified
New Settings
BASE_DIR
startproject - settings.py
startproject
• manage.py
• settings.py
• wsgi.py
• urls.py
admin enabled by default
startproject - urls.py
startapp
• admin.py
• models.py
• views.py
• tests.py
startapp
• admin.py
• models.py
• views.py
• tests.py
admin.py is generated by default
startapp - admin.py
startapp
• admin.py
• models.py
• views.py
• tests.py
Default Example TestCase is removed
startapp - tests.py
File
Django 1.5
Django 1.6
Change
Tar ball 8 M 6.6 M -17.5 %
settings.py 5.3 K 2.0 K -63.1 %
urls.py 556 297 -46.5 %
wsgi.py 1.4 K 387 -72.2 %
tests.py 383 60 -84.3 %
New Features
• Simple Layout
• Improved Transactions
• Persistent DB Connections
• Others
Improved Transactions (Biggest Change from 0.9x)
Old APIs were Deprecated
Transactions
New APIs were Introduced
Transactions
Transactions – New APIs
• Clean & Simple
• Improved Performance
• Improved Error Handling
• Fine grained rollbacks between savepoints
Improvements
Transactions – New APIs
• Enabled by default • Every single SQL Statement is committed immediately
• django.db.transaction.set_autocommit()
DB Level Auto Commit
Transactions – New APIs
atomic() • New Single API to control DB transactions
• Commit on Success
• Rollback on Exceptions
• It can be
• Nested
• Used as a Decorator & Context Manager
Transactions – New APIs – atomic()
Decorator
Transactions – New APIs – atomic()
Context Manager
Transactions
Backward Incompatible
https://docs.djangoproject.com/en/1.6/topics/db/transactions/
#transactions-upgrading-from-1-5
Transactions
Excellent Presentations by
Aymeric Augustin
https://myks.org/en/talks/
More Details
New Features
• Simple Layout
• Improved Transactions
• Persistent DB Connections
• Others
New Connection for every HTTP Request
Till Django 1.5
Persistent DB Connections
Same Connection will be reused between requests
In Django 1.6
Persistent DB Connections
• Life Time of a Database Connection
• Different for each Database
• Default = 0 (Off & No reuse)
• For Unlimited, use None
• Comply with DB Idle Connection Settings
CONN_MAX_AGE
Persistent DB Connections
• Connection is established during the first query
• Connection won’t be closed and reused for subsequent requests
• One Connection for each Worker Thread
• Once it is exceeds the CONN_MAX_AGE, it will be closed • Beginning & end of each request
Processing Behavior
Persistent DB Connections
New Features
• Simple Layout
• Improved Transactions
• Persistent DB Connections
• Others
Locates tests anywhere (test*.py)
New Test Runner
QuerySet.dates() is now Time Zone Aware
(Earlier Only in UTC)
QuerySet.dates() is now operates only on DateField() and returns datetime.date
"hour", "minute" or "second“ lookups are supported
QuerySet.datetimes() is operates on DateTimeField()
and returns datetime.datetime
BinaryField() is introduced
• Stores raw binary data in bytes
• Queryset is not possible
• Don’t use it to store static files
django-admin.py check • Verifies the setup for Current Version
• Settings
• Application Code
• Warnings will be issued for incompatibles
Efficient Model.save()
Before
SELECT is used to determine INSERT (or) UPDATE
Now
if instance has Primary Key, it is UPDATE
else, it is INSERT
Model.objects.earliest()
(latest() with reverse direction)
Model.objects.first()
• Returns the first object from QuerySet
• If no order specified, Ordered by PK
• None for EmptyQuerySet
Model.objects.first()
Model.objects.last()
Model.objects.filter(timestamp__hour = 23)
Model.objects.filter(timestamp__minute = 59)
Model.objects.filter(timestamp__second = 59)
ModelAdmin.preserve_filters
HTML 5 Types for input fields
(Email, URL and Number)
Supported in • IntegerField
• FloatField
• DecimalField
• EmailField
• URLField
Blank Password is Supported
• SQLite Save Points is supported
• Open Layer based GeoDjango Forms API
• Pillow is preferred over PIL for ImageField
• Django Admin jQuery is upgraded from 1.4.2 to 1.9.1
• New Deployment Check List (https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/)
Notable Changes
• UNUSABLE_PASSWORD is removed (is_password_usable)
• MAXIMUM_PASSWORD_LENGTH is removed in the latest security fix
• Password reset now uses Base64 Encoding (earlier it was base36)
• BooleanField is not default to False (None). Be Explicit
• django.db.models.query.EmptyQuerySet can’t be instantiated
• django-debug-toolbar is breaking
Dropped Features
django.contrib.localflavor
django.contrib.databrowse
django.contrib.markup
Deprecated Features
• django.middleware.transaction.TransactionMiddleware
• django.db.transaction.autocommit
• django.db.transaction.commit_on_success
• django.db.transaction.commit_manually
• TRANSACTIONS_MANAGED (in settings.py)
• CACHE_MIDDLEWARE_ANONYMOUS_ONLY
• SEND_BROKEN_LINK_EMAILS (django.middleware.common.BrokenLinkEmailsMiddleware)
django.contrib.comments
Django 1.7
In built migrations
References https://docs.djangoproject.com/en/dev/releases/1.6/ https://speakerdeck.com/julienphalip/django-1-dot-6-the-best-new-features-and-the-important-changes