def __init__(cls, class_name, bases, attrs): # Don't execute for Gallery itself if [b for b in bases if isinstance(b, GalleryBase)]: try: gallery_meta = getattr(cls, 'GalleryMeta') except AttributeError: raise GalleryMetaNotDefined('%s must define GalleryMeta.' % class_name) try: member_models = getattr(gallery_meta, 'member_models') except AttributeError: raise MemberModelsNotDefined( '%s.GalleryMeta must define a list of member_models.' % class_name) gallery_meta.gallery_class = cls cls._gallery_meta = gallery_meta membership_verbose_name = '%s Membership' % cls._meta.verbose_name custom_membership = getattr(gallery_meta, 'membership_class', None) if custom_membership: membership_class_name = '%sBaseMembership' % class_name else: membership_class_name = '%sMembership' % class_name module_name = cls.__module__ membership_class = _create_membership_class( class_name=membership_class_name, verbose_name=membership_verbose_name, app_label=cls._meta.app_label, module_name=module_name, member_models=member_models, abstract=bool(custom_membership), gallery_class=cls, ) if custom_membership: cls.BaseMembership = membership_class module = importlib.import_module(module_name) class Descriptor(object): def __get__(self, instance, owner): return getattr(module, custom_membership) cls.Membership = Descriptor() else: cls.Membership = membership_class ModelBase.__init__(cls, class_name, bases, attrs)
def __init__(self, name, bases, attrs): ModelBase.__init__(self, name, bases, attrs) if not self._meta.abstract: MetaQueue.IMPLEMENTATIONS.append(self)