Take a model class or model label and return its model label.

    >>> get_model_label(MyModel)
    "myapp.MyModel"

    >>> get_model_label("myapp.MyModel")
    "myapp.MyModel"
555053
def get_model_label(model):
    
    if isinstance(model, six.string_types):
        return model
    else:
        return "%s.%s" % (
            model._meta.app_label,
            model.__name__
        )
854139
def get(self, model, property_name):
        
        if type(model) is dict:
            if property_name not in model:
                return None
            else:
                return model[property_name]
        elif hasattr(model, 'get_' + property_name):
            getter = getattr(model, 'get_' + property_name)
            return getter()
        else:
            try:
                return getattr(model, property_name)
            except AttributeError:
                return None
1150054
def get_for_model(self, model):
        
        return self.get_or_create(
            content_type    = ContentType.objects.get_for_model(model),
            object_id       = model.pk
        )
544462
def model_get(method_name):
    

    def model_get(_value, context, **_params):
        method = getattr(context["model"], method_name)
        return _get(method, context["key"], (), {})

    return model_get
673202
def model_from_path(model_path, fuzziness=False):
    
    app_name = '.'.join(model_path.split('.')[:-1])
    model_name = model_path.split('.')[-1]

    if not app_name:
        return None

    module = importlib.import_module(app_name)
    try:
        model = getattr(module, model_name)
    except AttributeError:
        try:
            model = getattr(getattr(module, 'models'), model_name)
        except AttributeError:
            model = get_model(model_name, app_name, fuzziness=fuzziness)

    return model
273498
def get_model():
    
    if not hasattr(g, 'model'):
        g.model = load_model(current_app.config['MODEL_CLS_PATH'],
                             current_app.config['MODEL_CLS_NAME'],
                             current_app.config['MODEL_LOAD_ARGS'])
    return g.model
1066902
def model_page(self, request, app_label, model_name, rest_of_url=None):
        
        try:
            model = get_model(app_label, model_name)
        except LookupError:
            model = None

        if model is None:
            raise http.Http404("App %r, model %r, not found." %
                               (app_label, model_name))
        try:
            databrowse_class = self.registry[model]
        except KeyError:
            raise http.Http404("This model exists but has not been registered "
                               "with databrowse.")
        return databrowse_class(model, self).root(request, rest_of_url)
1117206
def dependency(app_label, model):
    
    from django.db.migrations import swappable_dependency
    return swappable_dependency(get_model_name(app_label, model))
328709
def lookup_field_label(self, context, field, default=None):
        
        # if this is a subfield, strip off everything but the last field name
        if field.find('.') >= 0:
            return self.lookup_field_label(context, field.split('.')[-1], default)

        label = None

        # is there a label specified for this field
        if field in self.field_config and 'label' in self.field_config[field]:
            label = self.field_config[field]['label']

        # if we were given a default, use that
        elif default:
            label = default

        # check our model
        else:
            for model_field in self.model._meta.fields:
                if model_field.name == field:
                    return model_field.verbose_name.title()

        # otherwise, derive it from our field name
        if label is None:
            label = self.derive_field_label(field)

        return label
117114
def get_model_class(self):
        """"""
        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()
347613
def get_rel_attr(self, attr_name, model):
        
        rel_attr_name, attr_name = attr_name.split(".", 1)
        rel_attr = getattr(self.model, rel_attr_name, None)
        rel_model = None
        attr = None

        if rel_attr is not None:
            rel_model = rel_attr.property.mapper.class_
            attr = getattr(rel_model, attr_name, None)

        return rel_model, attr
681084
def _get_model(self, appname, modelname):
        
        app = self._get_app(appname)
        models = app.get_models()
        model = None
        for mod in models:
            if mod.__name__ == modelname:
                model = mod
                return model
        msg = "Model " + modelname + " not found"
21810
def get_field(cls, model, opts, label, field):
    

    trans_model = model._meta.translation_model
    try:
        (f, lang_id) = trans_model._meta.translated_fields[field]
        return f
    except KeyError:
        # fall back to the old way -- see if model contains the field
        # directly
        pass

    try:
        return opts.get_field(field)
    except models.FieldDoesNotExist:
        raise ImproperlyConfigured("'%s.%s' refers to field '%s' that is " \
            "missing from model '%s'." \
            % (cls.__name__, label, field, model.__name__))
127499
def get_group_model():
    
    from django.apps import apps
    model_string = get_group_model_string()
    try:
        return apps.get_model(model_string)
    except ValueError:
        raise ImproperlyConfigured("JOYOUS_GROUP_MODEL must be of the form 'app_label.model_name'")
    except LookupError:
        raise ImproperlyConfigured(
            "JOYOUS_GROUP_MODEL refers to model '%s' that has not been installed" % model_string
        )
719181
def app_model_id(obj):
    
    ct = ContentType.objects.get_for_model(obj)

    return '%s-%s-%s' % (ct.app_label, ct.model, obj.id)
1085882
def find_model(sender, model_name):
    
    MC = get_mc()
    model = MC.get((MC.c.model_name==model_name) & (MC.c.uuid!=''))
    if model:
        model_inst = model.get_instance()
        orm.set_model(model_name, model_inst.table_name, appname=__name__, model_path='')
        return orm.__models__.get(model_name)
564326
def get_template_name(self, template_name_suffix=None):
        
        if isinstance(self.object, models.Model):
            meta = self.object._meta
            return self.get_template_path(meta, app_label=meta.app_label, object_name=meta.object_name, template_name_suffix=template_name_suffix)
        elif hasattr(self, 'model') and self.model is not None and issubclass(self.model, models.Model):
            meta = self.model._meta
            return self.get_template_path(meta, app_label=meta.app_label, object_name=meta.object_name, template_name_suffix=template_name_suffix)