Skip to content

Commit

Permalink
Adds compatibility for django 1.10 (gadventures#65)
Browse files Browse the repository at this point in the history
* Fix gadventures#63: AttributeError: Options object has no attribute get_field_by_name

* Fix gadventures#61: AttributeError: object has no attribute _deferred
  • Loading branch information
jrief authored and Craig Nagy committed Nov 21, 2016
1 parent 6220e2c commit de5db63
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions fsm_admin/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def fsm_field_instance(self, fsm_field_name):
Returns the actual state field instance, as opposed to
fsm_field attribute representing just the field name.
"""
return self.model._meta.get_field_by_name(fsm_field_name)[0]
return self.model._meta.get_field(fsm_field_name)

def display_fsm_field(self, obj, fsm_field_name):
"""
Expand Down Expand Up @@ -225,7 +225,7 @@ def _get_possible_transitions(self, obj):
"""
fsm_fields = self._get_fsm_field_list()
for field in fsm_fields:
fsmfield = obj._meta.get_field_by_name(field)[0]
fsmfield = obj._meta.get_field(field)
transitions = fsmfield.get_all_transitions(self.model)
for transition in transitions:
if transition.source in [getattr(obj, field), '*']:
Expand Down
5 changes: 4 additions & 1 deletion fsm_admin/templatetags/fsm_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django import template
from django.contrib.admin.templatetags.admin_modify import submit_row
from django.conf import settings
from django.db import models

register = template.Library()

Expand Down Expand Up @@ -47,7 +48,9 @@ def fsm_submit_row(context):
original = context.get('original', None)
model_name = ''
if original is not None:
if original._deferred:
# TODO: replace the following line by `original is models.DEFERRED`
# after dropping support for Django-1.9
if getattr(original, '_deferred', False) or original is getattr(models, 'DEFERRED', None):
model_name = type(original).__base__._meta.verbose_name
else:
model_name = original.__class__._meta.verbose_name
Expand Down

0 comments on commit de5db63

Please sign in to comment.