+ All Categories
Home > Internet > What's new in Django 1.7

What's new in Django 1.7

Date post: 28-Nov-2014
Category:
Upload: daniel-roseman
View: 302 times
Download: 6 times
Share this document with a friend
Description:
Slides from my AirConf presentation on the new features in Django 1.7
17

Click here to load reader

Transcript
Page 1: What's new in Django 1.7

What’s new in Django 1.7Daniel Roseman@danielroseman

blog.roseman.org.ukairpair.me/danielroseman

Page 2: What's new in Django 1.7

About me

Web developer previously at Google, Global Radio, Glasses Direct, GDSDjango user since version 0.95

Occasional blogger on Django, Python, vim

Top answerer for Django at StackOverflow

Page 3: What's new in Django 1.7

What is new

● Migrations● App loading● System checks● Managers from custom QuerySets● Prefetch object● Custom lookups and transforms● Form errors improvements

Page 4: What's new in Django 1.7

Migrations

Awesome!

But… functionality is basically the same as South

Page 5: What's new in Django 1.7

Automatic migrations

● Detects schema changes● Add/remove columns, indexes, tables● Dependencies

manage.py makemigrations <app>

manage.py migrate

Page 6: What's new in Django 1.7

Migrations

No separate datamigration commandMigrations no longer load initial_dataRunPython - arbitrary functionality: callable(apps, schema_editor)

RunSQL replaces deprecated initial SQL data loading

Page 7: What's new in Django 1.7

App registry

List of registered apps:from django.apps import apps

Consists of AppConfig instancesNo need for models.py Hook for “startup” codeAdmin autodiscover called automatically

Page 8: What's new in Django 1.7

AppConfigs

Can use path to AppConfig subclass as entry in INSTALLED_APPSOtherwise module is checked for default_app_config variableIf none, uses default classSet app label or verbose_nameready() method for startup code

Page 9: What's new in Django 1.7

Checks framework

Static checking for appsLoads of built-in checksCustom checks - eg on field subclasses, or base model classes

./manage.py check

Page 10: What's new in Django 1.7

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

Page 11: What's new in Django 1.7

Custom manager on relations

Choose which manager is used to return related querysetPre-filteringCalling custom methods

my_instance.related_set( manager='my_manager')

Page 12: What's new in Django 1.7

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

Page 13: What's new in Django 1.7

Lookups and Transforms

Custom lookups:MyModel.objects.filter(foo__ne='bar')

Transform comparisons:MyModel.objects.filter(foo__lq='bar')

Page 14: What's new in Django 1.7

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

Page 15: What's new in Django 1.7

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…

Page 16: What's new in Django 1.7

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

Page 17: What's new in Django 1.7

Recommended