What’s new in Django 1.7 
Daniel Roseman 
@danielroseman 
blog.roseman.org.uk 
airpair.me/danielroseman
About me 
Web developer previously at Google, Global 
Radio, Glasses Direct, GDS 
Django user since version 0.95 
Occasion...
What is new 
● Migrations 
● App loading 
● System checks 
● Managers from custom QuerySets 
● Prefetch object 
● Custom l...
Migrations 
Awesome! 
But… functionality is basically the same as 
South
Automatic migrations 
● Detects schema changes 
● Add/remove columns, indexes, tables 
● Dependencies 
manage.py makemigra...
Migrations 
No separate datamigration command 
Migrations no longer load initial_data 
RunPython - arbitrary functionality...
App registry 
List of registered apps: 
from django.apps import apps 
Consists of AppConfig instances 
No need for models....
AppConfigs 
Can use path to AppConfig subclass as entry in 
INSTALLED_APPS 
Otherwise module is checked for 
default_app_c...
Checks framework 
Static checking for apps 
Loads of built-in checks 
Custom checks - eg on field subclasses, or 
base mod...
Custom QuerySets 
Previously, create a custom Manager with extra 
methods - but it returns a plain QuerySet 
Instead, crea...
Custom manager on relations 
Choose which manager is used to return 
related queryset 
Pre-filtering 
Calling custom metho...
Prefetch object 
Control operation of prefetch_related() 
● Specify base QuerySet for lookup - eg to 
filter relation, or ...
Lookups and Transforms 
Custom lookups: 
MyModel.objects.filter(foo__ne='bar') 
Transform comparisons: 
MyModel.objects.fi...
Form errors 
Simpler way to add errors from clean() method 
or from the view: form.add_error() 
Get raw error objects: 
fo...
Miscellaneous 
● Field subclass deconstruct() method 
● QuerySet .update_or_create() 
● JsonResponse class 
● Template {% ...
The future 
GSoC student Daniel Pyrathon: refactoring 
Meta to stable API 
Allows any arbitrary class to define Meta and 
...
What's new in Django 1.7
Upcoming SlideShare
Loading in …5
×

What's new in Django 1.7

1,511 views

Published on

Slides from my AirConf presentation on the new features in Django 1.7

Published in: Internet
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,511
On SlideShare
0
From Embeds
0
Number of Embeds
38
Actions
Shares
0
Downloads
13
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

What's new in Django 1.7

  1. 1. What’s new in Django 1.7 Daniel Roseman @danielroseman blog.roseman.org.uk airpair.me/danielroseman
  2. 2. About me Web developer previously at Google, Global Radio, Glasses Direct, GDS Django user since version 0.95 Occasional blogger on Django, Python, vim Top answerer for Django at StackOverflow
  3. 3. What is new ● Migrations ● App loading ● System checks ● Managers from custom QuerySets ● Prefetch object ● Custom lookups and transforms ● Form errors improvements
  4. 4. Migrations Awesome! But… functionality is basically the same as South
  5. 5. Automatic migrations ● Detects schema changes ● Add/remove columns, indexes, tables ● Dependencies manage.py makemigrations <app> manage.py migrate
  6. 6. Migrations No separate datamigration command Migrations no longer load initial_data RunPython - arbitrary functionality: callable(apps, schema_editor) RunSQL replaces deprecated initial SQL data loading
  7. 7. App registry List of registered apps: from django.apps import apps Consists of AppConfig instances No need for models.py Hook for “startup” code Admin autodiscover called automatically
  8. 8. AppConfigs Can use path to AppConfig subclass as entry in INSTALLED_APPS Otherwise module is checked for default_app_config variable If none, uses default class Set app label or verbose_name ready() method for startup code
  9. 9. Checks framework Static checking for apps Loads of built-in checks Custom checks - eg on field subclasses, or base model classes ./manage.py check
  10. 10. Custom QuerySets Previously, create a custom Manager with extra methods - but it returns a plain QuerySet Instead, create custom QuerySet, and use as_manager() to create manager automatically
  11. 11. Custom manager on relations Choose which manager is used to return related queryset Pre-filtering Calling custom methods my_instance.related_set( manager='my_manager')
  12. 12. Prefetch object Control operation of prefetch_related() ● Specify base QuerySet for lookup - eg to filter relation, or call select_related() ● to_attr to save result to custom attribute ● can call multiple times with different querysets
  13. 13. Lookups and Transforms Custom lookups: MyModel.objects.filter(foo__ne='bar') Transform comparisons: MyModel.objects.filter(foo__lq='bar')
  14. 14. Form errors Simpler way to add errors from clean() method or from the view: form.add_error() Get raw error objects: form.errors.as_data() Serialize errors to JSON: form.errors.as_json() NON_FIELD_ERROR key in Meta.error_messages
  15. 15. Miscellaneous ● Field subclass deconstruct() method ● QuerySet .update_or_create() ● JsonResponse class ● Template {% include %} can use anything with a render method ● Lots more admin control - site_header, site_title, index_title, get_fields(), get_search_fields(), view_on_site…
  16. 16. The future GSoC student Daniel Pyrathon: refactoring Meta to stable API Allows any arbitrary class to define Meta and therefore make use of admin, model forms, etc Example: GMail store

×