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 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 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 Slide

  4. Migrations
    They're pretty good.

    View Slide

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

    View Slide

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

    View Slide

  7. A New Format
    More concise
    Declarative
    Introspectable

    View Slide

  8. Migration actions
    Frozen ORM

    View Slide

  9. View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  18. 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 Slide

  19. Important Upgrade Notes

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  24. Thanks.
    @andrewgodwin
    aeracode.org

    View Slide