Skip to content

Commit

Permalink
Fix for proxy model defined in external app.
Browse files Browse the repository at this point in the history
  • Loading branch information
paolodina committed Apr 2, 2016
1 parent f0a15e3 commit de8db9d
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions crudbuilder/abstract.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import django
try:
from django.apps import apps
except ImportError:
pass

import crudbuilder
from six import with_metaclass
from django.contrib.contenttypes.models import ContentType
Expand Down Expand Up @@ -38,8 +44,15 @@ def __init__(
@property
def get_model_class(self):
"""Returns model class"""
c = ContentType.objects.get(app_label=self.app, model=self.model)
return c.model_class()
try:
c = ContentType.objects.get(app_label=self.app, model=self.model)
except ContentType.DoesNotExist:
# try another kind of resolution
# fixes a situation where a proxy model is defined in some external app.
if django.VERSION >= (1, 7):
return apps.get_model(self.app, self.model)
else:
return c.model_class()

def _has_crud_attr(self, attr):
return getattr(self.crud, attr, None)
Expand Down

0 comments on commit de8db9d

Please sign in to comment.