Commit f901b4d6 authored by Aymeric Augustin's avatar Aymeric Augustin
Browse files

Took advantage of the new get_model API. Refs #21702.

parent 3c47786c
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -185,11 +185,11 @@ class ModelDetailView(BaseAdminDocsView):
    def get_context_data(self, **kwargs):
        # Get the model class.
        try:
            apps.get_app_config(self.kwargs['app_label'])
            app_config = apps.get_app_config(self.kwargs['app_label'])
        except LookupError:
            raise Http404(_("App %(app_label)r not found") % self.kwargs)
        try:
            model = apps.get_model(self.kwargs['app_label'], self.kwargs['model_name'])
            model = app_config.get_model(self.kwargs['model_name'])
        except LookupError:
            raise Http404(_("Model %(model_name)r not found in app %(app_label)r") % self.kwargs)

+2 −6
Original line number Diff line number Diff line
import inspect
import re

from django.apps import apps as django_apps
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured, PermissionDenied
from django.utils.module_loading import import_by_path
@@ -123,17 +124,12 @@ def get_user_model():
    """
    Returns the User model that is active in this project.
    """
    from django.apps import apps

    try:
        app_label, model_name = settings.AUTH_USER_MODEL.split('.')
        return django_apps.get_model(settings.AUTH_USER_MODEL)
    except ValueError:
        raise ImproperlyConfigured("AUTH_USER_MODEL must be of the form 'app_label.model_name'")
    try:
        user_model = apps.get_model(app_label, model_name)
    except LookupError:
        raise ImproperlyConfigured("AUTH_USER_MODEL refers to model '%s' that has not been installed" % settings.AUTH_USER_MODEL)
    return user_model


def get_user(request):
+2 −4
Original line number Diff line number Diff line
@@ -2,16 +2,14 @@
from __future__ import unicode_literals

from django.apps import apps
from django.conf import settings
from django.core import checks


def check_user_model(**kwargs):
    from django.conf import settings

    errors = []
    app_name, model_name = settings.AUTH_USER_MODEL.split('.')

    cls = apps.get_model(app_name, model_name)
    cls = apps.get_model(settings.AUTH_USER_MODEL)

    # Check that REQUIRED_FIELDS is a list
    if not isinstance(cls.REQUIRED_FIELDS, (list, tuple)):
+1 −1
Original line number Diff line number Diff line
@@ -49,7 +49,7 @@ def post_comment(request, next=None, using=None):
    if ctype is None or object_pk is None:
        return CommentPostBadRequest("Missing content_type or object_pk field.")
    try:
        model = apps.get_model(*ctype.split(".", 1))
        model = apps.get_model(ctype)
        target = model._default_manager.using(using).get(pk=object_pk)
    except TypeError:
        return CommentPostBadRequest(
+3 −4
Original line number Diff line number Diff line
@@ -65,9 +65,8 @@ class Command(BaseCommand):
        excluded_models = set()
        for exclude in excludes:
            if '.' in exclude:
                app_label, model_name = exclude.split('.', 1)
                try:
                    model = apps.get_model(app_label, model_name)
                    model = apps.get_model(exclude)
                except LookupError:
                    raise CommandError('Unknown model in excludes: %s' % exclude)
                excluded_models.add(model)
@@ -98,7 +97,7 @@ class Command(BaseCommand):
                    if app_config.models_module is None or app_config in excluded_apps:
                        continue
                    try:
                        model = apps.get_model(app_label, model_label)
                        model = app_config.get_model(model_label)
                    except LookupError:
                        raise CommandError("Unknown model: %s.%s" % (app_label, model_label))

@@ -177,7 +176,7 @@ def sort_dependencies(app_list):
            if hasattr(model, 'natural_key'):
                deps = getattr(model.natural_key, 'dependencies', [])
                if deps:
                    deps = [apps.get_model(*d.split('.')) for d in deps]
                    deps = [apps.get_model(dep) for dep in deps]
            else:
                deps = []

Loading