Improved app_label logic

This commit is contained in:
Syrus Akbary 2015-09-25 19:54:14 -07:00
parent 1ec2f5a4c3
commit e9cf8616ba
2 changed files with 8 additions and 3 deletions

View File

@ -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.

View File

@ -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: