blob: 3db58cfdbe922466bb083c8dab5e40650ccd064f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# -*- 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(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 model in models
for obj in six.itervalues(vars(model))
if isinstance(obj, GenericForeignKey))
for field in fields:
errors.extend(field.check())
return errors
|