def __new__(mcs, name, bases, attrs): meta = attrs.get("Meta") module = attrs.get("__module__") is_concrete = not getattr(meta, "abstract", False) app_label = getattr(meta, "app_label", "") if is_concrete and module and not app_label: if meta is None: meta = type("Meta", (), {}) app_label = get_app_label_from_import_path(module) meta.app_label = app_label meta.db_table = "{}_{}".format(app_label, name.lower()) # i think needs to be here even though it's set on base model, # because meta is not inherited (but not tested this) meta.use_strong_refs = True attrs["Meta"] = meta new_class = super().__new__(mcs, name, bases, attrs) if not hasattr(new_class._meta, 'use_strong_refs'): new_class._meta.use_strong_refs = False # 2015-12-22: this probably doesn't work anymore, # since we moved _choices to views.py # but we can tell users they can define FOO_choices in models.py, # and then call it in the equivalent method in views.py for f in new_class._meta.fields: if hasattr(new_class, f.name + '_choices'): attr_name = 'get_%s_display' % f.name setattr(new_class, attr_name, make_get_display(f)) return new_class
def __new__(cls, name, bases, attrs): meta = attrs.get("Meta") module = attrs.get("__module__") is_concrete = not getattr(meta, "abstract", False) app_label = getattr(meta, "app_label", "") if is_concrete and module and not app_label: if meta is None: meta = type("Meta", (), {}) app_label = get_app_label_from_import_path(module) meta.app_label = app_label meta.db_table = "{}_{}".format(app_label, name.lower()) attrs["Meta"] = meta # 2015-12-22: this probably doesn't work anymore, # since we moved _choices to views.py # but we can tell users they can define FOO_choices in models.py, # and then call it in the equivalent method in views.py new_class = super(OTreeModelBase, cls).__new__(cls, name, bases, attrs) for f in new_class._meta.fields: if hasattr(new_class, f.name + '_choices'): attr_name = 'get_%s_display' % f.name setattr(new_class, attr_name, make_get_display(f)) return new_class
def get_template_names(self): if self.template_name is not None: return [self.template_name] return [ '{}/{}.html'.format( get_app_label_from_import_path(self.__module__), self.__class__.__name__) ]
def get_template_names(self): if self.template_name is not None: template_name = self.template_name else: template_name = '{}/{}.html'.format( get_app_label_from_import_path(self.__module__), self.__class__.__name__) return [template_name]
def __new__(cls, name, bases, attrs): meta = attrs.get("Meta") module = attrs.get("__module__") is_concrete = not getattr(meta, "abstract", False) app_label = getattr(meta, "app_label", "") if is_concrete and module and not app_label: if meta is None: meta = type("Meta", (), {}) app_label = get_app_label_from_import_path(module) meta.app_label = app_label meta.db_table = "{}_{}".format(app_label, name.lower()) attrs["Meta"] = meta new_class = super(OTreeModelBase, cls).__new__(cls, name, bases, attrs) for f in new_class._meta.fields: if hasattr(new_class, f.name + '_choices'): attr_name = 'get_%s_display' % f.name setattr(new_class, attr_name, make_get_display(f)) return new_class