From e9cf8616ba5949810e0f8436e946bb8749840c5e Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Fri, 25 Sep 2015 19:54:14 -0700 Subject: [PATCH] Improved app_label logic --- graphene/core/types.py | 7 ++++++- graphene/core/utils.py | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/graphene/core/types.py b/graphene/core/types.py index 9b136458..e83591b1 100644 --- a/graphene/core/types.py +++ b/graphene/core/types.py @@ -33,7 +33,12 @@ class ObjectTypeMeta(type): meta = attr_meta base_meta = getattr(new_class, '_meta', None) - new_class.add_to_class('_meta', Options(meta, module)) + if '.' in module: + app_label, _ = module.rsplit('.', 1) + else: + app_label = module + + new_class.add_to_class('_meta', Options(meta, app_label)) if base_meta and base_meta.proxy: new_class._meta.interface = base_meta.interface # Add all attributes to the class. diff --git a/graphene/core/utils.py b/graphene/core/utils.py index d6ad10d4..69039d89 100644 --- a/graphene/core/utils.py +++ b/graphene/core/utils.py @@ -24,12 +24,12 @@ def get_registered_object_type(name, object_type=None): object_type_name = name if '.' in name: - app_label, object_type_name = name.split('.', 1) + app_label, object_type_name = name.rsplit('.', 1) elif object_type: app_label = object_type._meta.app_label # Filter all registered object types which have the same name - ots = [ot for ot in registered_object_types if ot._meta.type_name == name] + ots = [ot for ot in registered_object_types if ot._meta.type_name == object_type_name] # If the list have more than one object type with the name, filter by # the app_label if len(ots)>1 and app_label: