Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Django 1.7 And You

Django 1.7 And You

A talk I gave at the San Francisco Django Meetup group

Andrew Godwin

April 30, 2014
Tweet

More Decks by Andrew Godwin

Other Decks in Programming

Transcript

  1. 1.7
    Andrew Godwin
    @andrewgodwin
    & you

    View full-size slide

  2. Andrew Godwin
    Author of South migrations library
    Hi, I'm
    Author of 1.7 Django migrations
    Generally far too involved in Django

    View full-size slide

  3. Django 1.7
    Migrations
    Scheduled release: May 15th
    (we'll probably miss it)
    App loading refactor
    Checks framework
    select_related filters
    Custom lookups

    View full-size slide

  4. Migrations
    They're pretty good.

    View full-size slide

  5. The (second) Plan
    Django
    Schema backend
    ORM Hooks
    South 2
    Migration handling
    User interface
    Backport for 1.4 - 1.6

    View full-size slide

  6. Logically Separate
    Schema backend
    ORM Hooks
    Migration handling
    User interface
    SchemaEditor Migrations

    View full-size slide

  7. A New Format
    More concise
    Declarative
    Introspectable

    View full-size slide

  8. Migration actions
    Frozen ORM

    View full-size slide

  9. In-memory running
    Creates models from migration sets
    Autodetector diffs created from on-disk
    Used to feed SchemaEditor / ORM

    View full-size slide

  10. Backwards Compatability
    Auto-applies first migration if tables exist
    Ignores South-style migrations
    South will start looking for south_migrations

    View full-size slide

  11. App Loading
    Mostly internal change
    App objects per-app
    Start of long path away from settings

    View full-size slide

  12. Checks Framework
    Proper support for project-level validation
    Old validation moved in
    Upgrade warnings now possible

    View full-size slide

  13. from django.core.checks import register
    @register()
    def example_check(app_configs, **kwargs):
    errors = []
    # ... your check logic here
    return errors

    View full-size slide

  14. prefetch_related control
    Now accepts a Prefetch object
    Can customise order, select_related, or filter

    View full-size slide

  15. Pizza.objects.prefetch_related(
    Prefetch(
    'restaurants',
    queryset=Restaurant.objects.select_related('best_pizza'),
    )
    )

    View full-size slide

  16. Custom Lookups
    Allows for more powerful Field subclasses
    You can stop using .extra() and .raw() as much

    View full-size slide

  17. from django.db.models import Lookup
    class NotEqual(Lookup):
    lookup_name = 'ne'
    def as_sql(self, qn, connection):
    lhs, lhs_params = self.process_lhs(qn, connection)
    rhs, rhs_params = self.process_rhs(qn, connection)
    params = lhs_params + rhs_params
    return '%s <> %s' % (lhs, rhs), params

    View full-size slide

  18. Important Upgrade Notes

    View full-size slide

  19. Fields need deconstruct()
    It's a required new method for all fields.

    View full-size slide

  20. syncdb is deprecated
    Use migrate (old apps will still work)

    View full-size slide

  21. initial_data is dead
    Use data migrations and the ORM instead

    View full-size slide

  22. Django 1.8?
    LTS
    Migrations for contrib apps
    PostgreSQL improvements?

    View full-size slide

  23. Thanks.
    @andrewgodwin
    aeracode.org

    View full-size slide