mirror of
https://github.com/django/django.git
synced 2025-10-26 07:06:08 +00:00
Fixed #25746 -- Isolated inlined test models registration.
Thanks to Tim for the review.
This commit is contained in:
@@ -6,10 +6,22 @@ from django.conf import settings
|
||||
from django.core import checks
|
||||
|
||||
|
||||
def check_user_model(**kwargs):
|
||||
errors = []
|
||||
def check_user_model(app_configs=None, **kwargs):
|
||||
if app_configs is None:
|
||||
cls = apps.get_model(settings.AUTH_USER_MODEL)
|
||||
else:
|
||||
app_label, model_name = settings.AUTH_USER_MODEL.split('.')
|
||||
for app_config in app_configs:
|
||||
if app_config.label == app_label:
|
||||
cls = app_config.get_model(model_name)
|
||||
break
|
||||
else:
|
||||
# Checks might be run against a set of app configs that don't
|
||||
# include the specified user model. In this case we simply don't
|
||||
# perform the checks defined below.
|
||||
return []
|
||||
|
||||
cls = apps.get_model(settings.AUTH_USER_MODEL)
|
||||
errors = []
|
||||
|
||||
# Check that REQUIRED_FIELDS is a list
|
||||
if not isinstance(cls.REQUIRED_FIELDS, (list, tuple)):
|
||||
|
||||
@@ -1,17 +1,23 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from itertools import chain
|
||||
|
||||
from django.apps import apps
|
||||
from django.utils import six
|
||||
|
||||
|
||||
def check_generic_foreign_keys(**kwargs):
|
||||
def check_generic_foreign_keys(app_configs=None, **kwargs):
|
||||
from .fields import GenericForeignKey
|
||||
|
||||
if app_configs is None:
|
||||
models = apps.get_models()
|
||||
else:
|
||||
models = chain.from_iterable(app_config.get_models() for app_config in app_configs)
|
||||
errors = []
|
||||
fields = (obj
|
||||
for cls in apps.get_models()
|
||||
for obj in six.itervalues(vars(cls))
|
||||
for model in models
|
||||
for obj in six.itervalues(vars(model))
|
||||
if isinstance(obj, GenericForeignKey))
|
||||
for field in fields:
|
||||
errors.extend(field.check())
|
||||
|
||||
@@ -3,6 +3,7 @@ from __future__ import unicode_literals
|
||||
|
||||
import inspect
|
||||
import types
|
||||
from itertools import chain
|
||||
|
||||
from django.apps import apps
|
||||
from django.core.checks import Error, Tags, register
|
||||
@@ -11,21 +12,24 @@ from django.core.checks import Error, Tags, register
|
||||
@register(Tags.models)
|
||||
def check_all_models(app_configs=None, **kwargs):
|
||||
errors = []
|
||||
for model in apps.get_models():
|
||||
if app_configs is None or model._meta.app_config in app_configs:
|
||||
if not inspect.ismethod(model.check):
|
||||
errors.append(
|
||||
Error(
|
||||
"The '%s.check()' class method is "
|
||||
"currently overridden by %r." % (
|
||||
model.__name__, model.check),
|
||||
hint=None,
|
||||
obj=model,
|
||||
id='models.E020'
|
||||
)
|
||||
if app_configs is None:
|
||||
models = apps.get_models()
|
||||
else:
|
||||
models = chain.from_iterable(app_config.get_models() for app_config in app_configs)
|
||||
for model in models:
|
||||
if not inspect.ismethod(model.check):
|
||||
errors.append(
|
||||
Error(
|
||||
"The '%s.check()' class method is "
|
||||
"currently overridden by %r." % (
|
||||
model.__name__, model.check),
|
||||
hint=None,
|
||||
obj=model,
|
||||
id='models.E020'
|
||||
)
|
||||
else:
|
||||
errors.extend(model.check(**kwargs))
|
||||
)
|
||||
else:
|
||||
errors.extend(model.check(**kwargs))
|
||||
return errors
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user