What's new in Django 1.2?

  • 2,749 views
Uploaded on

Slides from my talk at Django-NYC.

Slides from my talk at Django-NYC.

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
2,749
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
63
Comments
0
Likes
2

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide
  • Thank you.

Transcript

  • 1. What’s new in Django 1.2? Jacob Kaplan-Moss
  • 2. Databases/Models
  • 3. GSo C Multiple databases http://bit.ly/multi-db
  • 4. # settings.py DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'mydb', }, 'other': { 'ENGINE': 'django.db.backends.sqlite3' 'NAME': '/path/to/db' } }
  • 5. >>> MyModel.objects.all() [...] >>> MyModel.objects.using('other').all() [...] >>> instance = MyModel(...) >>> instance.save(using='default')
  • 6. 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']
  • 7. Raw queries http://bit.ly/raw-sql
  • 8. >>> 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. ...
  • 9. GSo C Validators http://bit.ly/validators
  • 10. 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])
  • 11. Template improvements
  • 12. Improved CSRF protection http://bit.ly/django-csrf
  • 13. {% if x > y %} {% if x|lower = 'q' %} {% if x.y.z in list %}
  • 14. Cached template loading http://bit.ly/template-loaders
  • 15. New in django.contrib
  • 16. User messaging http://bit.ly/django-messages
  • 17. 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 %}
  • 18. Testing improvements
  • 19. ~40% faster
  • 20. Natural keys in fixtures http://bit.ly/natural-keys
  • 21. ./manage.py test --failfast
  • 22. Et cetera http://bit.ly/django-12
  • 23. Et cetera http://bit.ly/django-12 • Python 2.4+
  • 24. Et cetera http://bit.ly/django-12 • Python 2.4+ • Email backends
  • 25. Et cetera http://bit.ly/django-12 • Python 2.4+ • Email backends • QuerySet.exists()
  • 26. Et cetera http://bit.ly/django-12 • Python 2.4+ • Email backends • QuerySet.exists() • Class-based test runners
  • 27. Et cetera http://bit.ly/django-12 • Python 2.4+ • Email backends • QuerySet.exists() • Class-based test runners • Improvements to GeoDjango’s inspectdb
  • 28. 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
  • 29. 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
  • 30. 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
  • 31. 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
  • 32. 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
  • 33. When?
  • 34. When? • January 26: Django 1.2 beta.
  • 35. When? • January 26: Django 1.2 beta. • March 2: Django 1.2 release candidate.
  • 36. When? • January 26: Django 1.2 beta. • March 2: Django 1.2 release candidate. • March 9: Django 1.2 final.
  • 37. Questions? Me: Jacob Kaplan-Moss Email: jacob@jacobian.org Twitter: @jacobian