from django.contrib.sessions.models import Session


BUILTIN_SEQUENCES = {
    'django.contrib.auth': [],
    'django.contrib.contenttypes': [],
    'django.contrib.sessions': [],
}


# Starting in Django 1.3 alpha, Session.expire_date has a db_index set.
# This needs to be reflected in the evolutions. Rather than hard-coding
# a specific version to check for, we check the actual value in the field.
if Session._meta.get_field_by_name('expire_date')[0].db_index:
    BUILTIN_SEQUENCES['django.contrib.sessions'].append(
        'session_expire_date_db_index')

# Starting in Django 1.4 alpha, the Message model was deleted.
try:
    from django.contrib.auth.models import Message
except ImportError:
    BUILTIN_SEQUENCES['django.contrib.auth'].append('auth_delete_message')


# Starting with Django Evolution 0.7.0, we explicitly need ChangeMetas for
# unique_together.
BUILTIN_SEQUENCES['django.contrib.auth'].append(
    'auth_unique_together_baseline')
BUILTIN_SEQUENCES['django.contrib.contenttypes'].append(
    'contenttypes_unique_together_baseline')

from django.contrib.sessions.models import Session


BUILTIN_SEQUENCES = {
    'django.contrib.auth': [],
    'django.contrib.contenttypes': [],
    'django.contrib.sessions': [],
}


# Starting in Django 1.3 alpha, Session.expire_date has a db_index set.
# This needs to be reflected in the evolutions. Rather than hard-coding
# a specific version to check for, we check the actual value in the field.
if Session._meta.get_field('expire_date').db_index:
    BUILTIN_SEQUENCES['django.contrib.sessions'].append(
        'session_expire_date_db_index')

# Starting in Django 1.4 alpha, the Message model was deleted.
try:
    from django.contrib.auth.models import Message
except ImportError:
    BUILTIN_SEQUENCES['django.contrib.auth'].append('auth_delete_message')


# Starting with Django Evolution 0.7.0, we explicitly need ChangeMetas for
# unique_together.
BUILTIN_SEQUENCES['django.contrib.auth'].append(
    'auth_unique_together_baseline')
BUILTIN_SEQUENCES['django.contrib.contenttypes'].append(
    'contenttypes_unique_together_baseline')

Fix a field lookup to be compatible with all versions of Django.
Fix a field lookup to be compatible with all versions of Django.

Recent versions of Django removed Meta.get_field_by_name(), which our
built-in evolutions were trying to use. Fortunately, all supported
versions have Meta.get_field(), which works just as well. This change
switches over to that.

We'll want to revisit the built-in evolutions before release in order to
prevent possible conflicts with Django's migrations.

  from django.contrib.sessions.models import Session
  
  
  BUILTIN_SEQUENCES = {
      'django.contrib.auth': [],
      'django.contrib.contenttypes': [],
      'django.contrib.sessions': [],
  }
  
  
  # Starting in Django 1.3 alpha, Session.expire_date has a db_index set.
  # This needs to be reflected in the evolutions. Rather than hard-coding
  # a specific version to check for, we check the actual value in the field.
- if Session._meta.get_field_by_name('expire_date')[0].db_index:
+ if Session._meta.get_field('expire_date').db_index:
      BUILTIN_SEQUENCES['django.contrib.sessions'].append(
          'session_expire_date_db_index')
  
  # Starting in Django 1.4 alpha, the Message model was deleted.
  try:
      from django.contrib.auth.models import Message
  except ImportError:
      BUILTIN_SEQUENCES['django.contrib.auth'].append('auth_delete_message')
  
  
  # Starting with Django Evolution 0.7.0, we explicitly need ChangeMetas for
  # unique_together.
  BUILTIN_SEQUENCES['django.contrib.auth'].append(
      'auth_unique_together_baseline')
  BUILTIN_SEQUENCES['django.contrib.contenttypes'].append(
      'contenttypes_unique_together_baseline')
  
Fix a field lookup to be compatible with all versions of Django.
## Code Before:
from django.contrib.sessions.models import Session


BUILTIN_SEQUENCES = {
    'django.contrib.auth': [],
    'django.contrib.contenttypes': [],
    'django.contrib.sessions': [],
}


# Starting in Django 1.3 alpha, Session.expire_date has a db_index set.
# This needs to be reflected in the evolutions. Rather than hard-coding
# a specific version to check for, we check the actual value in the field.
if Session._meta.get_field_by_name('expire_date')[0].db_index:
    BUILTIN_SEQUENCES['django.contrib.sessions'].append(
        'session_expire_date_db_index')

# Starting in Django 1.4 alpha, the Message model was deleted.
try:
    from django.contrib.auth.models import Message
except ImportError:
    BUILTIN_SEQUENCES['django.contrib.auth'].append('auth_delete_message')


# Starting with Django Evolution 0.7.0, we explicitly need ChangeMetas for
# unique_together.
BUILTIN_SEQUENCES['django.contrib.auth'].append(
    'auth_unique_together_baseline')
BUILTIN_SEQUENCES['django.contrib.contenttypes'].append(
    'contenttypes_unique_together_baseline')

## Instruction:
Fix a field lookup to be compatible with all versions of Django.
## Code After:
from django.contrib.sessions.models import Session


BUILTIN_SEQUENCES = {
    'django.contrib.auth': [],
    'django.contrib.contenttypes': [],
    'django.contrib.sessions': [],
}


# Starting in Django 1.3 alpha, Session.expire_date has a db_index set.
# This needs to be reflected in the evolutions. Rather than hard-coding
# a specific version to check for, we check the actual value in the field.
if Session._meta.get_field('expire_date').db_index:
    BUILTIN_SEQUENCES['django.contrib.sessions'].append(
        'session_expire_date_db_index')

# Starting in Django 1.4 alpha, the Message model was deleted.
try:
    from django.contrib.auth.models import Message
except ImportError:
    BUILTIN_SEQUENCES['django.contrib.auth'].append('auth_delete_message')


# Starting with Django Evolution 0.7.0, we explicitly need ChangeMetas for
# unique_together.
BUILTIN_SEQUENCES['django.contrib.auth'].append(
    'auth_unique_together_baseline')
BUILTIN_SEQUENCES['django.contrib.contenttypes'].append(
    'contenttypes_unique_together_baseline')
