Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.

What's new in Django 1.2?

Slides from my talk at Django-NYC.

  • Identifiez-vous pour voir les commentaires

What's new in Django 1.2?

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

×